public void Subset_if_Second_Set_Includes_One_Set() { PowerSet <int> testSet = new PowerSet <int>(); testSet.Put(2); testSet.Put(3); testSet.Put(4); testSet.Put(5); PowerSet <int> set2 = new PowerSet <int>(); set2.Put(1); set2.Put(2); set2.Put(3); set2.Put(4); set2.Put(5); set2.Put(6); set2.Put(7); set2.Put(8); bool isSubset = testSet.IsSubset(set2); Assert.IsTrue(testSet.Size() == 4); Assert.IsFalse(isSubset); Assert.IsTrue(set2.Size() == 8); }
public void SizeTest() { PowerSet <string> s1 = new PowerSet <string>(); if (s1.Size() != 0) { Assert.Fail(); } s1.Put("erer"); if (s1.Size() != 1) { Assert.Fail(); } s1.Put("erer"); if (s1.Size() != 1) { Assert.Fail(); } s1.Put("erere"); if (s1.Size() != 2) { Assert.Fail(); } s1.Put("serer"); s1.Put("erer"); if (s1.Size() != 3) { Assert.Fail(); } s1.Remove("erer"); if (s1.Size() != 2) { Assert.Fail(); } }
public void Union_both_Sets_has_values() { PowerSet <int> testSet = new PowerSet <int>(); testSet.Put(1); testSet.Put(2); testSet.Put(3); testSet.Put(4); PowerSet <int> set2 = new PowerSet <int>(); set2.Put(5); set2.Put(6); set2.Put(7); set2.Put(8); PowerSet <int> interSet = testSet.Union(set2); Assert.IsTrue(interSet.Size() == 8); Assert.IsTrue(interSet.Get(1)); Assert.IsTrue(interSet.Get(2)); Assert.IsTrue(interSet.Get(3)); Assert.IsTrue(interSet.Get(4)); Assert.IsTrue(interSet.Get(5)); Assert.IsTrue(interSet.Get(6)); Assert.IsTrue(interSet.Get(7)); Assert.IsTrue(interSet.Get(8)); }
public void TestPut_Int_1() { PowerSet <int> ps1 = new PowerSet <int>(); Assert.AreEqual(0, ps1.Size()); ps1.Put(1); ps1.Put(2); ps1.Put(3); ps1.Put(6); Assert.AreEqual(4, ps1.Size()); Assert.AreEqual(true, ps1.Get(1)); Assert.AreEqual(true, ps1.Get(2)); Assert.AreEqual(true, ps1.Get(3)); Assert.AreEqual(true, ps1.Get(6)); Assert.AreEqual(false, ps1.Get(5)); ps1.Put(5); Assert.AreEqual(5, ps1.Size()); Assert.AreEqual(true, ps1.Get(5)); }
public void TestEUnion_1() { PowerSet <string> ps1 = new PowerSet <string>(); PowerSet <string> ps2 = new PowerSet <string>(); ps1.Put("j1"); ps1.Put("j2"); ps1.Put("car"); ps1.Put("far"); ps2.Put("Pop"); ps2.Put("far"); ps2.Put("j2"); ps2.Put("trust"); ps2.Put("bleach"); Assert.AreEqual(4, ps1.Size()); Assert.AreEqual(5, ps2.Size()); PowerSet <string> ps3 = ps1.Union(ps2); Assert.AreEqual(7, ps3.Size()); Assert.AreEqual(true, ps3.Get("far")); Assert.AreEqual(true, ps3.Get("j2")); Assert.AreEqual(true, ps3.Get("car")); Assert.AreEqual(true, ps3.Get("j1")); Assert.AreEqual(true, ps3.Get("Pop")); Assert.AreEqual(true, ps3.Get("trust")); Assert.AreEqual(true, ps3.Get("bleach")); Assert.AreEqual(false, ps3.Get("forest")); }
public void RemoveTest() { PowerSet <int> set = new PowerSet <int>(); set.Put(1); set.Put(1); set.Put(2); set.Put(2); set.Put(3); Assert.True(set.Size() == 3); Assert.True(set.Get(1)); Assert.True(set.Get(2)); Assert.True(set.Get(3)); Assert.True(!set.Get(4)); Assert.True(set.Remove(3)); Assert.True(set.Size() == 2); Assert.True(set.Get(1)); Assert.True(set.Get(2)); Assert.True(!set.Get(3)); Assert.True(set.Remove(2)); Assert.True(set.Size() == 1); Assert.True(set.Get(1)); Assert.True(!set.Get(2)); Assert.True(!set.Get(3)); Assert.True(!set.Remove(2)); Assert.True(!set.Remove(3)); }
public void TestPut_Node_1() { PowerSet <Node> ps1 = new PowerSet <Node>(); Node node1 = new Node(0); Node node2 = new Node(1); Node node3 = new Node(2); Node node4 = new Node(3); Node node5 = new Node(4); ps1.Put(node1); ps1.Put(node2); ps1.Put(node3); ps1.Put(node4); Assert.AreEqual(4, ps1.Size()); Assert.AreEqual(true, ps1.Get(node1)); Assert.AreEqual(true, ps1.Get(node2)); Assert.AreEqual(true, ps1.Get(node3)); Assert.AreEqual(true, ps1.Get(node4)); Assert.AreEqual(false, ps1.Get(node5)); ps1.Put(node5); Assert.AreEqual(5, ps1.Size()); Assert.AreEqual(true, ps1.Get(node5)); }
public static void TestsPowerSetDifference() { var testPowerSet1 = new PowerSet <int>(); var testPowerSet2 = new PowerSet <int>(); Assert.AreEqual(0, testPowerSet1.Size()); Assert.AreEqual(0, testPowerSet2.Size()); testPowerSet1.Put(1); Assert.AreEqual(1, testPowerSet1.Size()); Assert.IsTrue(testPowerSet1.Get(1)); testPowerSet1.Put(2); Assert.AreEqual(2, testPowerSet1.Size()); Assert.IsTrue(testPowerSet1.Get(1)); Assert.IsTrue(testPowerSet1.Get(2)); testPowerSet1.Put(3); Assert.AreEqual(3, testPowerSet1.Size()); Assert.IsTrue(testPowerSet1.Get(1)); Assert.IsTrue(testPowerSet1.Get(2)); Assert.IsTrue(testPowerSet1.Get(3)); testPowerSet2.Put(1); Assert.AreEqual(1, testPowerSet2.Size()); Assert.IsTrue(testPowerSet2.Get(1)); testPowerSet2.Put(3); Assert.AreEqual(2, testPowerSet2.Size()); Assert.IsTrue(testPowerSet2.Get(1)); Assert.IsTrue(testPowerSet2.Get(3)); var result = testPowerSet1.Difference(testPowerSet2); Assert.AreEqual(1, result.Size()); Assert.IsTrue(result.Get(2)); }
public PowerSet <T> Union(PowerSet <T> set2) { // объединение текущего множества и set2 var currValues = WhereIsNotNull(slots); var set2Values = WhereIsNotNull(set2.slots); var result = new PowerSet <T>(base.Size() + set2.Size()); foreach (var currValue in currValues) { var obj = (T)Convert.ChangeType(currValue, typeof(T)); result.Put(obj); var status = Get_Put_status(); if (status != PUT_OK || status != PUT_ALREADYHAS) { union_status = UNION_ERR; return(result); } } foreach (var value in set2Values) { var obj = (T)Convert.ChangeType(value, typeof(T)); result.Put(obj); var status = Get_Put_status(); if (status != PUT_OK || status != PUT_ALREADYHAS) { union_status = UNION_ERR; return(result); } } union_status = UNION_OK; return(result); }
public void GeneralTestusingCount() { PowerSet <int> iii = new PowerSet <int>(); iii.Put(10); if (iii.Size() != 1) { Assert.Fail(); } iii.Put(10); if (iii.Size() != 1) { Assert.Fail(); } iii.Put(20); if (iii.Size() != 2) { Assert.Fail(); } iii.Remove(10); if (iii.Size() != 1) { Assert.Fail(); } if (!iii.Get(20)) { Assert.Fail(); } }
public void TestEPut_2() { PowerSet <int> ps1 = new PowerSet <int>(); int n1 = 52; int n2 = 174; int n3 = 9; Assert.AreEqual(0, ps1.Size()); ps1.Put(n1); ps1.Put(n2); ps1.Put(n3); Assert.AreEqual(true, ps1.Get(n1)); Assert.AreEqual(true, ps1.Get(n2)); Assert.AreEqual(true, ps1.Get(n3)); Assert.AreEqual(3, ps1.Size()); ps1.Put(9); Assert.AreEqual(3, ps1.Size()); for (int i = 200; i < 300; i++) { ps1.Put(i); } Assert.AreEqual(103, ps1.Size()); for (int i = 200; i < 300; i++) { Assert.AreEqual(true, ps1.Get(i)); } }
public void TestDifference_Int_1A() { PowerSet <int> ps1 = new PowerSet <int>(); PowerSet <int> ps2 = new PowerSet <int>(); PowerSet <int> ps3; for (int i = 1; i <= 10; i++) { ps1.Put(i); } ps2.Put(3); ps2.Put(6); ps2.Put(7); ps2.Put(10); ps3 = ps1.Difference(ps2); Assert.AreEqual(6, ps3.Size()); Assert.AreEqual(true, ps3.Get(1)); Assert.AreEqual(true, ps3.Get(2)); Assert.AreEqual(true, ps3.Get(4)); Assert.AreEqual(true, ps3.Get(5)); Assert.AreEqual(true, ps3.Get(8)); Assert.AreEqual(true, ps3.Get(9)); Assert.AreEqual(false, ps3.Get(3)); Assert.AreEqual(false, ps3.Get(6)); Assert.AreEqual(false, ps3.Get(7)); Assert.AreEqual(false, ps3.Get(10)); for (int i = 11; i < 20000; i++) { Assert.AreEqual(false, ps3.Get(i)); } }
public void Test_Get_WhenNoValue() { var set = new PowerSet <int>(); set.Put(1); set.Put(2); set.Put(1); Assert.AreEqual(false, set.Get(3)); }
public void Test_Put_WhenSameValue() { var set = new PowerSet <int>(); set.Put(1); set.Put(2); set.Put(1); Assert.AreEqual(2, set.Size()); }
public void PutTest() { PowerSet <int> set = new PowerSet <int>(); set.Put(1); set.Put(1); set.Put(2); Assert.True(set.Size() == 2); }
public void Test_Get_WhenValueExists() { var set = new PowerSet <string>(); set.Put("a"); set.Put("b"); set.Put("a"); Assert.AreEqual(true, set.Get("b")); Assert.AreEqual(false, set.Get("k")); }
public void Test_Union_WhenSecondSetIsEmpty() { // возвращает true если value удалено // иначе false var set1 = new PowerSet <int>(); var set2 = new PowerSet <int>(); set1.Put(1); set1.Put(2); var result = set1.Union(set2); Assert.AreEqual(2, result.Size()); }
public void Test_Difference_WhenFirstSetIsEmpty() { // возвращает true если value удалено // иначе false var set1 = new PowerSet <int>(); var set2 = new PowerSet <int>(); set2.Put(1); set2.Put(3); var result = set1.Difference(set2); Assert.AreEqual(0, result.Size()); }
public void Put_if_Set_Already_Has_This_Elem() { PowerSet <string> strSet = new PowerSet <string>(); strSet.Put("word"); Assert.IsTrue(strSet.Size() == 1); Assert.IsTrue(strSet.Get("word")); strSet.Put("word"); Assert.IsTrue(strSet.Size() == 1); }
public void IsSubsetDifferent() { var s1 = new PowerSet <int>(); var s2 = new PowerSet <int>(); s1.Put(1); s1.Put(2); s2.Put(3); s2.Put(4); Assert.True(!s1.IsSubset(s2)); }
public void TestPut_String_3() { PowerSet <string> ps1 = new PowerSet <string>(); Assert.AreEqual(0, ps1.Size()); ps1.Put(""); Assert.AreEqual(1, ps1.Size()); Assert.AreEqual(true, ps1.Get("")); ps1.Put(" "); Assert.AreEqual(2, ps1.Size()); Assert.AreEqual(true, ps1.Get(" ")); }
public void DifferenceSame() { var s1 = new PowerSet <int>(); var s2 = new PowerSet <int>(); s1.Put(2); s1.Put(3); s2.Put(2); s2.Put(3); var union = s1.Difference(s2); Assert.True(union.Size() == 0); }
public void IsSubsetInternal() { var s1 = new PowerSet <int>(); var s2 = new PowerSet <int>(); s1.Put(1); s1.Put(2); s1.Put(3); s1.Put(4); s2.Put(3); s2.Put(4); Assert.True(s1.IsSubset(s2)); }
public void Union() { var s1 = new PowerSet <int>(); var s2 = new PowerSet <int>(); s1.Put(1); s1.Put(2); s2.Put(2); s2.Put(3); var union = s1.Union(s2); Assert.True(union.Size() == 3); }
public void TestPut_String_4() { PowerSet <string> ps1 = new PowerSet <string>(); ps1.Put("word"); ps1.Put("string"); ps1.Put("chars"); Assert.AreEqual(3, ps1.Size()); ps1.Put("word"); ps1.Put("string"); Assert.AreEqual(3, ps1.Size()); }
public void TestPut_Char_4() { PowerSet <char> ps1 = new PowerSet <char>(); ps1.Put(' '); ps1.Put('5'); ps1.Put('a'); Assert.AreEqual(3, ps1.Size()); ps1.Put('5'); ps1.Put('a'); Assert.AreEqual(3, ps1.Size()); }
public void TestPut_Float_4() { PowerSet <float> ps1 = new PowerSet <float>(); ps1.Put(0.3f); ps1.Put(3.2f); ps1.Put(32.1f); Assert.AreEqual(3, ps1.Size()); ps1.Put(3.2f); ps1.Put(32.1f); Assert.AreEqual(3, ps1.Size()); }
public void TestPut_Int_4() { PowerSet <int> ps1 = new PowerSet <int>(); ps1.Put(3); ps1.Put(32); ps1.Put(321); Assert.AreEqual(3, ps1.Size()); ps1.Put(3); ps1.Put(32); Assert.AreEqual(3, ps1.Size()); }
public void IntersectionDifferent() { var s1 = new PowerSet <int>(); var s2 = new PowerSet <int>(); s1.Put(1); s1.Put(2); s2.Put(3); s2.Put(4); var union = s1.Intersection(s2); Assert.True(union.Size() == 0); }
public void Test_Intersection_WhenFirstSetIsEmpty() { // возвращает true если value удалено // иначе false var set1 = new PowerSet <int>(); var set2 = new PowerSet <int>(); set2.Put(1); set2.Put(2); var result = set1.Intersection(set2); Assert.AreEqual(0, result.Size()); Assert.AreEqual(false, result.Get(1)); Assert.AreEqual(false, result.Get(2)); }