본문 바로가기

TIL Temp

test

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using NUnit.Framework;


namespace RandomValue.Library.Tests

{

    [TestFixture]

    public class RandomValueCreatorTests

    {

        [Test]

        public void Creator_WhenDefault_Return0or1()

        {

            int output = RandomValueCreator.GetZeroOrOne(2);


            Assert.AreEqual(0, output, 1);

            Assert.AreEqual(1, output, 1);

        }


        [Test]

        public void Creator_When2_Return0or1()

        {

            int input = 2;

            int output = RandomValueCreator.GetRandom(input);


            Assert.AreEqual(0, output, 1);

        }


        [Test]

        public void Creator_WhenDefault_Return(

            [Values(0, 1, 2, 3, 4, 5, 6 , 7, 8)] int input)

        {

            int output = RandomValueCreator.GetRandom(input);


            if(input == 0)

                Assert.Pass();

            if (output >= 0 && output <= input - 1)

                Assert.Pass();

            else

                Assert.Fail();

        }




    }

}



---------------

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using NUnit.Framework;


namespace RandomValue.Library.Tests

{

    [TestFixture]

    public class RandomValueCreatorTests

    {

        [Test]

        public void Creator_WhenDefault_Return0or1()

        {

            int output = RandomValueCreator.GetZeroOrOne(2);


            Assert.AreEqual(0, output, 1);

            Assert.AreEqual(1, output, 1);

        }


        [Test]

        public void Creator_When2_Return0or1()

        {

            int input = 2;

            int output = RandomValueCreator.GetRandom(input);


            Assert.AreEqual(0, output, 1);

        }


        [Test]

        public void Creator_WhenDefault_Return(

            [Values(0, 1, 2, 3, 4, 5, 6 , 7, 8)] int input)

        {

            int output = RandomValueCreator.GetRandom(input);


            if(input == 0)

                Assert.Pass();

            if (output >= 0 && output <= input - 1)

                Assert.Pass();

            else

                Assert.Fail();

        }




    }

}

------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RandomValue.Library;

namespace RandomValue
{
    class Program
    {
        static void Main(string[] args)
        {
            // 0, 1, 2, 3, 4 중 랜덤하게 호출합니다
            int output = RandomValueCreator.GetRandom(0);
            Console.WriteLine(output);

            Console.ReadLine();
        }
    }
}