public void Test_Revive() { //arrange int[] PRIME_ARRAY = { 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61,67, 71, 73, 79, 83, 89, 97 }; Random random = new Random(); int index = random.Next(1, PRIME_ARRAY.Length); int prime = PRIME_ARRAY[index]; NearPrime obj = new NearPrime(prime); int validNumber = random.Next(2, prime); int invalidNumber = random.Next(-10, 2); //act obj.Mod(invalidNumber); if (!obj.getActive()) { obj.Revive(); } bool expectedState = true; int expectedValue = 0; int upperNumber = prime; int lowerNumber = prime; bool found = false; while (!found) { if (++upperNumber % validNumber == 0) { found = true; expectedValue = upperNumber; } else if (--lowerNumber >= validNumber && lowerNumber % validNumber == 0) { found = true; expectedValue = lowerNumber; } } //assert Assert.AreEqual(expectedValue, obj.Mod(validNumber)); Assert.AreEqual(expectedState, obj.getActive()); }
public void Test_Revive_When_Active() { //arrange int[] PRIME_ARRAY = { 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61,67, 71, 73, 79, 83, 89, 97 }; Random random = new Random(); int index = random.Next(1, PRIME_ARRAY.Length); int prime = PRIME_ARRAY[index]; NearPrime obj = new NearPrime(prime); //act if (obj.getActive()) { obj.Revive(); } bool expectedState = false; //assert Assert.AreEqual(expectedState, obj.getActive()); }