public void TestMajoiryAlgo() { int?m = MajorityAlgo.FindMajorityElement(new int[] { 3, 3, 4, 2, 4, 4, 2, 4, 4 }); Assert.AreEqual(4, m, "Majority element should be 4"); m = MajorityAlgo.FindMajorityElement(new int[] { 3, 3, 4, 2, 4, 4, 2, 4, }); Assert.AreEqual(null, m, "Majority element should be null"); m = MajorityAlgo.FindMajorityElement(new int[] { 3, 4, 3, 2, 3, 2 }); Assert.AreEqual(null, m, "Majority element should be null"); m = MajorityAlgo.FindMajorityElement(new int[] { 3, 4, 3, 2, 3, 2, 2 }); Assert.AreEqual(null, m, "Majority element should be null"); m = MajorityAlgo.FindMajorityElement(new int[] { 3, 4, 3, 2, 3, 2, 3 }); Assert.AreEqual(3, m, "Majority element should be 3"); m = MajorityAlgo.FindMajorityElement(new int[] {}); Assert.AreEqual(null, m, "Majority element should be null"); m = MajorityAlgo.FindMajorityElement(null); Assert.AreEqual(null, m, "Majority element should be null"); m = MajorityAlgo.FindMajorityElement(new int[] { 3 }); Assert.AreEqual(3, m, "Majority element should be 3"); m = MajorityAlgo.FindMajorityElement(new int[] { 3, 4 }); Assert.AreEqual(null, m, "Majority element should be null"); m = MajorityAlgo.FindMajorityElement(new int[] { 3, 4, 3 }); Assert.AreEqual(3, m, "Majority element should be 3"); }
public void TestMajoiryAlgo_2N() { var m = MajorityAlgo.FindMajorityElement_2NElements(null); Assert.AreEqual(null, m, "Majority element should be null"); m = MajorityAlgo.FindMajorityElement_2NElements(new int[] { }); Assert.AreEqual(null, m, "Majority element should be null"); m = MajorityAlgo.FindMajorityElement_2NElements(new int[] { 1 }); Assert.AreEqual(null, m, "Majority element should be null"); m = MajorityAlgo.FindMajorityElement_2NElements(new int[] { 1, 2 }); Assert.AreEqual(1, m, "Majority element should be 1"); m = MajorityAlgo.FindMajorityElement_2NElements(new int[] { 1, 1 }); Assert.AreEqual(null, m, "Majority element should be null"); m = MajorityAlgo.FindMajorityElement_2NElements(new int[] { 1, 2, 1 }); Assert.AreEqual(null, m, "Majority element should be null"); m = MajorityAlgo.FindMajorityElement_2NElements(new int[] { 1, 2, 2, 3 }); Assert.AreEqual(2, m, "Majority element should be 2"); m = MajorityAlgo.FindMajorityElement_2NElements(new int[] { 1, 2, 3, 1 }); Assert.AreEqual(1, m, "Majority element should be 1"); m = MajorityAlgo.FindMajorityElement_2NElements(new int[] { 1, 2, 1, 3, 1, 4 }); Assert.AreEqual(1, m, "Majority element should be 1"); m = MajorityAlgo.FindMajorityElement_2NElements(new int[] { 1, 2, 1, 1, 4, 3 }); Assert.AreEqual(1, m, "Majority element should be 1"); m = MajorityAlgo.FindMajorityElement_2NElements(new int[] { 1, 2, 3, 1, 4, 1 }); Assert.AreEqual(1, m, "Majority element should be 1"); m = MajorityAlgo.FindMajorityElement_2NElements(new int[] { 1, 2, 3, 2, 4, 2 }); Assert.AreEqual(2, m, "Majority element should be 2"); }