public void LotOfZeroTest() { int[] a = new int[500]; //Throwing possible exceptions int[] result = AlgosFromCodility.CountingPositiveElements(a); Assert.AreEqual(new int[] { 500 }, result); }
public void ArrayWithAllZeroTest() { int[] A, B; int[] a = new int[50]; //Throwing possible exceptions AlgosFromCodility.CountingNegativePositiveElements(a, out A, out B); Assert.AreEqual(new [] { 50 }, A); Assert.AreEqual(null, B); }
public void ArrayBisNullTest() { bool catchException = false; try { AlgosFromCodility.SwapElements(new int[5], null); } catch (ArgumentNullException) { catchException = true; } if (catchException) { Assert.Pass(); } else { Assert.Fail(); } }
public static int Solution(int[] A) { long[] Prefix = AlgosFromCodility.PrefixSum(A); long min = long.MaxValue; int index; //Looking for int x = 0, y = 0; for (int i = A.Length - 1; i >= 1; i--) { long sliceCount = AlgosFromCodility.TotalOfSlice(Prefix, (uint)i - 1, (uint)i); if (sliceCount <= min) { min = sliceCount; x = i - 1; y = i; } } for (int i = y; i < A.Length; i++) { long sliceCount = AlgosFromCodility.TotalOfSlice(Prefix, (uint)x, (uint)i); if (sliceCount <= min) { min = sliceCount; } } for (int i = x; i >= 0; i--) { long sliceCount = AlgosFromCodility.TotalOfSlice(Prefix, (uint)i, (uint)y); if (sliceCount <= min) { x = i; } } return(x); }
public void ExampleTrueTest() { Assert.AreEqual(true, AlgosFromCodility.SwapElements(new [] { 5, 0, -3, 4 }, new [] { 2, 5, 4, -1, 0 })); }
public void OnlyPositivTest() { Assert.AreEqual(false, AlgosFromCodility.SwapElements(new [] { 5, 3 }, new [] { 3, 1, 1 })); }
public void OnlyNegativeTest() { Assert.AreEqual(true, AlgosFromCodility.SwapElements(new [] { -5, -3 }, new [] { -2, -1, -3 })); }
public void OnePositiveOneNegativeTest() { Assert.AreEqual(true, AlgosFromCodility.SwapElements(new [] { -10, 4, -1, 2 }, new [] { -8, 5, 2, 4, -6, 6 })); }
public void ExampleFalseTest() { Assert.AreEqual(false, AlgosFromCodility.SwapElements(new [] { 4, 0, -3, 4 }, new [] { 2, 5, 4, -1, 0 })); }