static void Main(string[] args) { var random = new Random(); var hoge = new PerfectSquares(); while (true) { var min = random.Next(0, 1000000000); var max = random.Next(min, 1000000000); var maxN = random.Next(2, 31); Console.WriteLine($"{min} {max} {maxN}"); var tested = hoge.countRange(min, max, maxN); var guchoku = Guchoku(min, max, maxN); Console.WriteLine($"tested : {tested}"); Console.WriteLine($"guchoku: {guchoku}"); if (tested == guchoku) { Console.WriteLine("OK"); Console.WriteLine(); } else { Console.WriteLine("NG"); Console.ReadKey(); } } }
public void PerfectSquareTest1() { Assert.AreEqual(false, PerfectSquares.IsSquare(-1), "negative numbers aren't square numbers"); Assert.AreEqual(false, PerfectSquares.IsSquare(3), "3 isn't a square number"); Assert.AreEqual(true, PerfectSquares.IsSquare(4), "4 is a square number"); Assert.AreEqual(true, PerfectSquares.IsSquare(25), "25 is a square number"); Assert.AreEqual(false, PerfectSquares.IsSquare(26), "26 isn't a square number"); }
public void Example0() { long minimum = 1L; long maximum = 10L; int maxN = 3; int __expected = 4; int __result = new PerfectSquares().countRange(minimum, maximum, maxN); Assert.AreEqual(__expected, __result); }
public void UserTest3() { long minimum = 2L; long maximum = 64L; int maxN = 6; int __expected = 10; int __result = new PerfectSquares().countRange(minimum, maximum, maxN); Assert.AreEqual(__expected, __result); }
public void UserTest() { long minimum = 1L; long maximum = 100000000000L; int maxN = 30; int __expected = -1; int __result = new PerfectSquares().countRange(minimum, maximum, maxN); Assert.AreEqual(__expected, __result); }
static void Main(string[] args) { PerfectSquares p = new PerfectSquares(); Console.WriteLine(p.IsPerfectSquare(3)); Console.WriteLine("#################"); var crono = new Stopwatch(); crono.Start(); foreach (int i in p.EagerPerfectSquares(10, 100)) Console.WriteLine(i); crono.Stop(); long ticksEager = crono.ElapsedTicks; Console.WriteLine("Eager version: {0:N} ticks.", ticksEager); Console.WriteLine("################"); var crono1 = new Stopwatch(); crono1.Start(); foreach (int i in p.LazyPerfectSquares(10, 100)) Console.WriteLine(i); crono1.Stop(); long ticksEager1 = crono1.ElapsedTicks; Console.WriteLine("Lazy version: {0:N} ticks.", ticksEager1); Console.WriteLine("######### TEST FOREACH #######"); int[] t = Enumerable.Range(0, 20).ToArray(); t.ForEach(Console.Write, integer => Console.Write(", ")); Console.WriteLine(); t.ForEachOdd((x) => Console.Write("{0} ", x)); Console.WriteLine(); //t.ForEachNth(); Console.WriteLine("############### LAST EXERCISE ##############"); int[] testArray = {1,9,6,5,8,7,85,8,4,5,2,33,5,66,8,5,4,2,5,5,2,1,4,5,2,6}; int[] testArray2 = {5,6,8,95,2,1,5,6,3,1,4,5,8,9,6,3,2,5,6,54,87,1,4,52,3}; //max value Console.WriteLine(testArray.Aggregate((x, y) => x>y ? x: y)); //difference testArray.Where(x => !testArray2.Contains(x)).ForEach(x => Console.Write("{0}, ", x)); Console.WriteLine(); //duplicates int[] withoutDuplicates = testArray.GroupBy(x => x).Select(y => y.FirstOrDefault()).ToArray(); withoutDuplicates.ForEach(x => Console.Write("{0}, ", x)); //s^2 Console.WriteLine(); int media = (testArray.Aggregate((x, y) => x+y))/testArray.Length; int varianza = (testArray.Aggregate((x, y) => ((x-media)*(x-media)) + ((y-media)*(y-media))))/testArray.Length; Console.WriteLine(varianza); //Last exercise Console.WriteLine(); Console.WriteLine(testArray.Where((x) => x % 2 == 0).Select((x) => x*x).Aggregate((x, y) => x+y)); }
public void TestMethod1(int n, int expected) { // Arrange PerfectSquares question = new PerfectSquares(); // Act int actual = question.NumSquares(n); // Assert Assert.AreEqual(expected, actual); }
public static void Main(string[] args) { MaxLoot.Test(); return; PerfectSquares.Test(); CountTriplets.Test(); TrianglePath.Test(); FindBusiest.Test(); DeletionDistance.Test(); ShuffleCards.Test(); PowerSet.Test(); //SmallestNonNegativeNumber.Test(); MaxSubsetSum.Test(); Graph.Test(); RankFromStream.Test(); SearchInsert.Test(); RemoveElementTest.TestRemoveElement(); MergeSortedLists.TestMergeTwoLists(); }