public void PUT_GetContract([PexAssumeUnderTest] ArrayList arrList, int index) { AssumePrecondition.IsTrue(index < arrList.Count && index >= 0); int Old_arrListCount = arrList.Count; int Old_index = index; //code int New_Ret = (int)(arrList[index]); int New_arrListCount = arrList.Count; bool New_containsNewRet = arrList.Contains(New_Ret); PexObserve.ValueForViewing("$old_arrList_Count", Old_arrListCount); PexObserve.ValueForViewing("$new_arrList_Count", New_arrListCount); PexObserve.ValueForViewing("$old_arrList_index", Old_index); PexObserve.ValueForViewing("$New_ret", New_Ret); PexObserve.ValueForViewing("$new_containsNewRet", New_containsNewRet); Assert.True(((New_containsNewRet && New_arrListCount <= Old_arrListCount && Old_arrListCount <= New_arrListCount && (!(New_arrListCount <= Old_index)) && Old_index >= 0))); }
public void PUT_CountContract([PexAssumeUnderTest] Stack.Stack <int> s1) { AssumePrecondition.IsTrue(true); //int Old_Ret = PexChoose.Value<int>("old_ret"); int Old_Top = s1.Count > 0 ? s1.Peek() : PexChoose.Value <int>("old_top"); /*Code */ int New_Ret = s1.Count; int New_Top = s1.Count > 0 ? s1.Peek() : PexChoose.Value <int>("new_top"); //int New_Top = Old_Top; // consult about this decision later //bool New_ContainsNewRet = s1.Contains(New_Ret); PexObserve.ValueForViewing("$old_s1_Peek", Old_Top); PexObserve.ValueForViewing("$new_s1_Peek", New_Top); //PexObserve.ValueForViewing("$old_s1_ret", Old_Ret); PexObserve.ValueForViewing("$new_ret", New_Ret); //PexObserve.ValueForViewing("$New_ContainsNewRet", New_ContainsNewRet); Assert.True(((Old_Top <= New_Ret && New_Ret >= 0) || (New_Top == Old_Top && New_Ret >= 0 && Old_Top >= 1) || (New_Top == Old_Top && New_Ret == 0) || (New_Ret == 0 && New_Top >= 1) || (New_Top <= Old_Top && New_Ret == 0) || (New_Top <= Old_Top && New_Top <= 0 && New_Ret == 0))); }
public void PUT_AddContract([PexAssumeUnderTest] BinaryHeap.BinaryHeap <int, int> bh, int key, int value) { AssumePrecondition.IsTrue(true); int Old_bhCount = bh.Count; //int Old_bhCapacity = bh.Capacity; int Old_bhMinimumKey = bh.Count > 0 ? bh.Minimum().Key : PexChoose.Value <int>("old_bhMinimumKey"); int Old_bhMinimumValue = bh.Count > 0 ? bh.Minimum().Value : PexChoose.Value <int>("old_bhMinimumValue"); //int Old_bhMinimumKey = bh.Count > 0 ? bh.Minimum().Key : key + 1; //PexChoose.Value<int>("old_bhMinimumKey"); //int Old_bhMinimumValue = bh.Count > 0 ? bh.Minimum().Value : value + 1; //PexChoose.Value<int>("old_bhMinimumValue"); int Old_bhIndexOfValue = bh.IndexOf(value); int Old_key = key; int Old_value = value; //code bh.Add(key, value); int New_bhCount = bh.Count; //int New_bhCapacity = bh.Capacity; int New_bhMinimumKey = bh.Minimum().Key; // bh.Count > 0 ? bh.Minimum().Key : PexChoose.Value<int>("new_bhMinimumKey"); int New_bhMinimumValue = bh.Minimum().Value; //bh.Count > 0 ? bh.Minimum().Value : PexChoose.Value<int>("new_bhMinimumValue"); int New_bhIndexOfValue = bh.IndexOf(value); PexObserve.ValueForViewing("$old_bh_count", Old_bhCount); PexObserve.ValueForViewing("$new_bh_count", New_bhCount); PexObserve.ValueForViewing("$old_bh_key", Old_key); PexObserve.ValueForViewing("$old_bh_value", Old_value); //PexObserve.ValueForViewing("$old_bh_capacity", Old_bhCapacity); //PexObserve.ValueForViewing("$new_bh_capacity", New_bhCapacity); PexObserve.ValueForViewing("$old_bh_indexof_value", Old_bhIndexOfValue); PexObserve.ValueForViewing("$new_bh_indexof_value", New_bhIndexOfValue); PexObserve.ValueForViewing("$old_bh_minimum_key", Old_bhMinimumKey); PexObserve.ValueForViewing("$new_bh_minimum_key", New_bhMinimumKey); PexObserve.ValueForViewing("$old_bh_minimum_value", Old_bhMinimumValue); PexObserve.ValueForViewing("$new_bh_minimum_value", New_bhMinimumValue); Assert.True(((New_bhMinimumKey <= Old_key && New_bhCount == 1 + Old_bhCount && (!(Old_bhIndexOfValue == Old_bhCount)) && Old_bhIndexOfValue <= Old_bhCount && New_bhIndexOfValue <= Old_bhCount && New_bhIndexOfValue >= 0 && Old_bhIndexOfValue >= -1))); }
public void RemoveTreePUT([PexAssumeUnderTest] List <int> values, int start, int end) { PexAssume.IsFalse(start < 0 || end < 0); PexAssume.IsTrue(start < values.Count); PexAssume.IsTrue(end >= start && end < values.Count); AvlTree <int> avlTree = new AvlTree <int>(values); int toRemoveCount = (end - start) == 0 ? (values.Count > 0? 1:0) : end - start; IList <int> toRemove = values.GetRange(start, toRemoveCount); foreach (int i in toRemove) { bool result = avlTree.Remove(i); PexAssert.IsTrue(result); } PexAssert.AreEqual(values.Count - toRemoveCount, avlTree.Count); IEnumerable enumerator = avlTree.GetInorderEnumerator(); foreach (int i in enumerator) { PexObserve.ValueForViewing <int>("tree nodes", i); } }
public void MergeOrderedArrayPUT(int[] input1, int[] input2) { if (input1 == null || input2 == null) { Sorting.MergeOrdered(input1, input2); PexAssert.IsTrue(false, "ArgumentNullException was expected"); } input1.ShellSort(); input2.ShellSort(); PexObserve.ValueForViewing <IList <int> >("Sorted Input1", input1); PexObserve.ValueForViewing <IList <int> >("Sorted Input2", input2); IList <int> result = Sorting.MergeOrdered(input1, input2); IList <int> expected = Sorting.Concatenate(input1, input2, new int[0]).MergeSort(); PexObserve.ValueForViewing <IList <int> >("Sorting.MergeSort", result); PexObserve.ValueForViewing <IList <int> >("Concatenate Output", expected); for (int i = 0; i < result.Count; i++) { PexAssert.AreEqual(expected[i], result[i]); } }
public void PUT_ContainsContract([PexAssumeUnderTest] Stack.Stack <int> s1, int x) { int undefinedTop = PexChoose.Value <int>("old_top"); AssumePrecondition.IsTrue(true); int Old_s1Count = s1.Count; int Old_Top = s1.Count > 0 ? s1.Peek() : undefinedTop; /*Code */ bool New_Ret = s1.Contains(x); int New_s1Count = s1.Count; //int New_Top = s1.Count > 0 ? s1.Peek() : undefinedTop; int New_Top = s1.Count > 0 ? s1.Peek() : PexChoose.Value <int>("new_top"); PexObserve.ValueForViewing("$old_s1_Count", Old_s1Count); PexObserve.ValueForViewing("$new_s1_Count", New_s1Count); PexObserve.ValueForViewing("$old_s1_Peek", Old_Top); PexObserve.ValueForViewing("$new_s1_Peek", New_Top); PexObserve.ValueForViewing("$new_ret", New_Ret); Assert.True(((New_s1Count == Old_s1Count && (!(New_Ret)) && New_s1Count >= 0) || (New_s1Count == Old_s1Count && New_Top == Old_Top && New_s1Count >= 1))); }
public void PUT_RemoveContract([PexAssumeUnderTest] Dictionary.Dictionary <int, int> d, int x) { AssumePrecondition.IsTrue(true); int Old_dCount = d.Count; int Old_x = x; bool Old_dContainsKeyX = d.ContainsKey(x); bool New_Ret = d.Remove(x); int New_dCount = d.Count; bool New_dContainsKeyX = d.ContainsKey(x); PexObserve.ValueForViewing("$old_d_Count", Old_dCount); PexObserve.ValueForViewing("$new_d_Count", New_dCount); PexObserve.ValueForViewing("$old_d_x", Old_x); PexObserve.ValueForViewing("$New_ret", New_Ret); PexObserve.ValueForViewing("$old_d_contains_key_x", Old_dContainsKeyX); PexObserve.ValueForViewing("$new_d_contains_key_x", New_dContainsKeyX); Assert.True((((!(New_dContainsKeyX)) && (!(Old_dContainsKeyX)) && New_dCount == Old_dCount && (!(New_Ret)) && Old_dCount >= 0) || ((!(New_dContainsKeyX)) && New_Ret && Old_dContainsKeyX && New_dCount == -1 + Old_dCount && New_dCount >= 0))); }
public void PUT_GetContract([PexAssumeUnderTest] ArrayList arrList, int index) { AssumePrecondition.IsTrue(index < arrList.Count && index >= 0); int Old_arrListCount = arrList.Count; //int Old_Ret = 2; int Old_index = index; int New_Ret = (int)(arrList[index]); int New_arrListCount = arrList.Count; int New_index = index; PexObserve.ValueForViewing("$old_arrList_Count", Old_arrListCount); PexObserve.ValueForViewing("$new_arrList_Count", New_arrListCount); PexObserve.ValueForViewing("$old_arrList_index", Old_index); PexObserve.ValueForViewing("$new_arrList_index", New_index); //PexObserve.ValueForViewing("$Old_ret", Old_Ret); PexObserve.ValueForViewing("$New_ret", New_Ret); Assert.True((New_arrListCount == Old_arrListCount && New_index == Old_index && Old_index != Old_arrListCount && New_index != Old_arrListCount && Old_index != New_arrListCount && New_index != New_arrListCount)); }
public void PUT_ContainsValueContract([PexAssumeUnderTest] Dictionary.Dictionary <int, int> d, int y) { AssumePrecondition.IsTrue(true); int Old_dCount = d.Count; int Old_y = y; //bool Old_dContainsValueY = d.ContainsValue(y); bool New_Ret = d.ContainsValue(y); int New_dCount = d.Count; //bool New_dContainsValueY = d.ContainsValue(y); PexObserve.ValueForViewing("$old_d_Count", Old_dCount); PexObserve.ValueForViewing("$new_d_Count", New_dCount); PexObserve.ValueForViewing("$old_d_y", Old_y); PexObserve.ValueForViewing("$New_ret", New_Ret); //PexObserve.ValueForViewing("$old_d_contains_value_y", Old_dContainsValueY); //PexObserve.ValueForViewing("$new_d_contains_value_y", New_dContainsValueY); Assert.True(((New_dCount == Old_dCount && (!(New_Ret)) && Old_dCount >= 0) || (New_dCount == Old_dCount && Old_dCount >= 1))); }
public void PUT_ContainsContract([PexAssumeUnderTest] HashSet.HashSet <int> hs, int x) { AssumePrecondition.IsTrue(true); int Old_hsCount = hs.Count; int Old_x = x; bool Old_hsContainsX = hs.Contains(x); bool New_Ret = hs.Contains(x); int New_hsCount = hs.Count; int New_x = x; bool New_hsContainsX = hs.Contains(x); PexObserve.ValueForViewing("$old_hs_Count", Old_hsCount); PexObserve.ValueForViewing("$new_hs_Count", New_hsCount); PexObserve.ValueForViewing("$old_x", Old_x); PexObserve.ValueForViewing("$new_x", New_x); PexObserve.ValueForViewing("$New_ret", New_Ret); PexObserve.ValueForViewing("$old_hs_contains_x", Old_hsContainsX); PexObserve.ValueForViewing("$new_hs_contains_x", New_hsContainsX); Assert.True(((New_hsCount == Old_hsCount && New_x == Old_x) && ((((New_Ret && Old_hsContainsX) && (((New_x == Old_hsCount && Old_x == Old_hsCount && Old_x == New_hsCount) && New_x == New_hsCount) || ((Old_x != Old_hsCount && New_x != Old_hsCount && Old_x != New_hsCount && New_x != New_hsCount) && (!(New_x == New_hsCount))))) && New_hsContainsX) || ((((!(New_Ret)) && (!(Old_hsContainsX))) && (((New_x == Old_hsCount && Old_x == Old_hsCount && Old_x == New_hsCount) && New_x == New_hsCount) || ((Old_x != Old_hsCount && New_x != Old_hsCount && Old_x != New_hsCount && New_x != New_hsCount) && (!(New_x == New_hsCount))))) && (!(New_hsContainsX)))))); }
public void PUT_CountContract([PexAssumeUnderTest] Queue.Queue <int> s1) { AssumePrecondition.IsTrue(true); int Old_s1Count = s1.Count; //int Old_Ret = PexChoose.Value<int>("old_ret"); int Old_Top = s1.Count > 0 ? s1.Peek() : PexChoose.Value <int>("old_top"); /*Code */ int New_Ret = s1.Count; int New_s1Count = s1.Count; int New_Top = Old_Top; // consult about this decision later PexObserve.ValueForViewing("$old_s1_Count", Old_s1Count); PexObserve.ValueForViewing("$new_s1_Count", New_s1Count); PexObserve.ValueForViewing("$old_s1_Peek", Old_Top); PexObserve.ValueForViewing("$new_s1_Peek", New_Top); //PexObserve.ValueForViewing("$old_s1_ret", Old_Ret); PexObserve.ValueForViewing("$new_ret", New_Ret); Assert.True(((New_Top == Old_Top && New_Ret == Old_s1Count && New_Ret == New_s1Count))); }
public void PUT_RemoveAtContract([PexAssumeUnderTest] BinaryHeap.BinaryHeap <int, int> bh, int index) { AssumePrecondition.IsTrue(index < bh.Count && index >= 0); int Old_bhCount = bh.Count; int Old_bhCapacity = bh.Capacity; int Old_bhMinimumKey = bh.Minimum().Key; int Old_bhMinimumValue = bh.Minimum().Value; int Old_index = index; //code var ra = bh.RemoveAt(index); int New_Ret_Key = ra.Key; int New_Ret_Value = ra.Value; int New_bhCount = bh.Count; int New_bhCapacity = bh.Capacity; int New_bhMinimumKey = bh.Count > 0 ? bh.Minimum().Key: PexChoose.Value <int>("new_min_key"); int New_bhMinimumValue = bh.Count > 0 ? bh.Minimum().Value : PexChoose.Value <int>("new_min_val"); int New_index = index; PexObserve.ValueForViewing("$old_bh_count", Old_bhCount); PexObserve.ValueForViewing("$new_bh_count", New_bhCount); PexObserve.ValueForViewing("$old_bh_capacity", Old_bhCapacity); PexObserve.ValueForViewing("$new_bh_capacity", New_bhCapacity); PexObserve.ValueForViewing("$old_bh_minimum_key", Old_bhMinimumKey); PexObserve.ValueForViewing("$new_bh_minimum_key", New_bhMinimumKey); PexObserve.ValueForViewing("$old_bh_minimum_value", Old_bhMinimumValue); PexObserve.ValueForViewing("$new_bh_minimum_value", New_bhMinimumValue); PexObserve.ValueForViewing("$old_bh_index", Old_index); PexObserve.ValueForViewing("$new_bh_index", New_index); PexObserve.ValueForViewing("$new_ret_key", New_Ret_Key); PexObserve.ValueForViewing("$new_ret_value", New_Ret_Value); Assert.IsTrue(false); }
public void PUT_AddContract([PexAssumeUnderTest] Dictionary.Dictionary <int, int> d, int x, int y) { AssumePrecondition.IsTrue(!(d.ContainsKey(x))); int Old_dCount = d.Count; int Old_x = x; int Old_y = y; bool Old_dContainsKeyX = d.ContainsKey(x); bool Old_dContainsKeyY = d.ContainsKey(y); bool Old_dContainsValueX = d.ContainsValue(x); bool Old_dContainsValueY = d.ContainsValue(y); d.Add(x, y); int New_dCount = d.Count; bool New_dContainsKeyX = d.ContainsKey(x); bool New_dContainsKeyY = d.ContainsKey(y); bool New_dContainsValueX = d.ContainsValue(x); bool New_dContainsValueY = d.ContainsValue(y); PexObserve.ValueForViewing("$old_d_Count", Old_dCount); PexObserve.ValueForViewing("$new_d_Count", New_dCount); PexObserve.ValueForViewing("$old_d_x", Old_x); PexObserve.ValueForViewing("$old_d_y", Old_y); //PexObserve.ValueForViewing("$Old_dContainsValueX", Old_dContainsValueX); //PexObserve.ValueForViewing("$New_dContainsValueX", New_dContainsValueX); //PexObserve.ValueForViewing("$Old_dContainsKeyY", Old_dContainsKeyY); //PexObserve.ValueForViewing("$New_dContainsKeyY ", New_dContainsKeyY); PexObserve.ValueForViewing("$old_d_contains_key_x", Old_dContainsKeyX); PexObserve.ValueForViewing("$new_d_contains_key_x", New_dContainsKeyX); PexObserve.ValueForViewing("$old_d_contains_value_y", Old_dContainsValueY); PexObserve.ValueForViewing("$new_d_contains_value_y", New_dContainsValueY); Assert.True((((!(Old_dContainsKeyX)) && New_dCount == 1 + Old_dCount && New_dContainsKeyX && New_dContainsValueY && (!(Old_dContainsValueY)) && New_dCount >= 1) || ((!(Old_dContainsKeyX)) && New_dCount == 1 + Old_dCount && New_dContainsKeyX && New_dContainsValueY && Old_dCount >= 1))); }
public void PUT_RemoveAtContract([PexAssumeUnderTest] BinaryHeap.BinaryHeap <int, int> bh, int index) { AssumePrecondition.IsTrue(index < bh.Count && index >= 0); int Old_bhCount = bh.Count; int Old_bhMinimumKey = bh.Minimum().Key; int Old_bhMinimumValue = bh.Minimum().Value; int Old_index = index; //bool Old_removeAtRoot = index == 0; //code var ra = bh.RemoveAt(index); int New_Ret_Key = ra.Key; int New_Ret_Value = ra.Value; int New_bhCount = bh.Count; int New_bhMinimumKey = bh.Count > 0 ? bh.Minimum().Key: PexChoose.Value <int>("new_min_key"); //int New_bhMinimumKey = bh.Count > 0 ? bh.Minimum().Key : Old_bhMinimumKey-1; int New_bhMinimumValue = bh.Count > 0 ? bh.Minimum().Value : PexChoose.Value <int>("new_min_val"); //int New_bhMinimumValue = bh.Count > 0 ? bh.Minimum().Value : Old_bhMinimumValue - 1; PexObserve.ValueForViewing("$old_bh_count", Old_bhCount); PexObserve.ValueForViewing("$new_bh_count", New_bhCount); PexObserve.ValueForViewing("$old_bh_minimum_key", Old_bhMinimumKey); PexObserve.ValueForViewing("$new_bh_minimum_key", New_bhMinimumKey); PexObserve.ValueForViewing("$old_bh_minimum_value", Old_bhMinimumValue); PexObserve.ValueForViewing("$new_bh_minimum_value", New_bhMinimumValue); PexObserve.ValueForViewing("$old_bh_index", Old_index); PexObserve.ValueForViewing("$new_ret_key", New_Ret_Key); PexObserve.ValueForViewing("$new_ret_value", New_Ret_Value); Assert.True(((Old_index <= New_bhCount && New_bhCount == -1 + Old_bhCount && Old_bhMinimumKey <= New_Ret_Key && Old_index >= 0))); }
public void PUT_AddVertexContract([PexAssumeUnderTest] UndirectedGraph.UndirectedGraph <int, Edge <int> > ug, int x) { AssumePrecondition.IsTrue(!ug.ContainsVertex(x)); int Old_ugVertexCount = ug.VertexCount; int Old_ugEdgeCount = ug.EdgeCount; //int Old_ugAdjacentDegree = -1; int Old_ugAdjacentDegree = PexChoose.Value <int>("old_ugAdjacentDegree"); int Old_x = x; bool Old_ugAllowParallelEdges = ug.AllowParallelEdges; bool Old_ugContainsVertexX = ug.ContainsVertex(x); //code ug.AddVertex(x); int New_ugVertexCount = ug.VertexCount; int New_ugEdgeCount = ug.EdgeCount; int New_ugAdjacentDegree = ug.AdjacentDegree(x); int New_x = x; bool New_ugAllowParallelEdges = ug.AllowParallelEdges; bool New_ugContainsVertexX = ug.ContainsVertex(x); PexObserve.ValueForViewing("$old_ug_vertex_count", Old_ugVertexCount); PexObserve.ValueForViewing("$new_ug_vertex_count", New_ugVertexCount); PexObserve.ValueForViewing("$old_ug_edge_count", Old_ugEdgeCount); PexObserve.ValueForViewing("$new_ug_edge_count", New_ugEdgeCount); PexObserve.ValueForViewing("$old_ug_adjacent_degree", Old_ugAdjacentDegree); PexObserve.ValueForViewing("$new_ug_adjacent_degree", New_ugAdjacentDegree); PexObserve.ValueForViewing("$old_ug_x", Old_x); PexObserve.ValueForViewing("$new_ug_x", New_x); PexObserve.ValueForViewing("$old_ug_contains_x", Old_ugContainsVertexX); PexObserve.ValueForViewing("$new_ug_contains_x", New_ugContainsVertexX); PexObserve.ValueForViewing("$old_ug_allow_parallel_edges", Old_ugAllowParallelEdges); PexObserve.ValueForViewing("$new_ug_allow_parallel_edges", New_ugAllowParallelEdges); PexAssert.IsTrue(false); }
public string FooTest( [PexAssumeUnderTest] Bar target, Foo iksDee, bool b, bool c ) { PexAssume.IsNotNull(iksDee); string result = target.Foo(iksDee, b, c); PexAssume.IsNotNull(target); int i = PexChoose.Value <int>("i"); PexObserve.ValueForViewing <int>("yo_add_this_thing", i); PexObserve.Value <string>("Hello, World!", "Foo"); string helloWorld = PexChoose.Value <string>("Hello, World!"); Console.WriteLine(helloWorld); return(result); // TODO: add assertions to method BarTest.FooTest(Bar, Foo, Boolean, Boolean) }
public void PUT_CountContract([PexAssumeUnderTest] Queue.Queue <int> s1) { AssumePrecondition.IsTrue(true); //int Old_s1Count = s1.Count; int Old_Top = s1.Count > 0 ? s1.Peek() : PexChoose.Value <int>("old_top"); /*Code */ int New_Ret = s1.Count; //int New_s1Count = s1.Count; int New_Top = s1.Count > 0 ? s1.Peek() : PexChoose.Value <int>("new_top"); //int New_Top = Old_Top; // alternate semantics //bool New_ContainsNewRet = s1.Contains(New_Ret); //PexObserve.ValueForViewing("$old_s1_Count", Old_s1Count); //PexObserve.ValueForViewing("$new_s1_Count", New_s1Count); PexObserve.ValueForViewing("$old_s1_Peek", Old_Top); PexObserve.ValueForViewing("$new_s1_Peek", New_Top); PexObserve.ValueForViewing("$new_ret", New_Ret); //PexObserve.ValueForViewing("$new_containsNewRet", New_ContainsNewRet); Assert.True(((New_Top == Old_Top && New_Ret >= 0) || New_Ret == 0)); }
public void PUT_PopContract([PexAssumeUnderTest] Stack.Stack <int> s1) { AssumePrecondition.IsTrue(s1.Count > 0); int Old_s1Count = s1.Count; int Old_Top = s1.Peek(); /*code*/ int New_Ret = s1.Pop(); //Old_ret = New_ret; int New_Top = s1.Count > 0 ? s1.Peek() : PexChoose.Value <int>("old_top"); //int New_Top = s1.Count > 0 ? s1.Peek() : Old_Top - 1; int New_s1Count = s1.Count; bool New_ContainsNewRet = s1.Contains(New_Ret); PexObserve.ValueForViewing("$Old_s1_Count", Old_s1Count); PexObserve.ValueForViewing("$New_s1_Count", New_s1Count); PexObserve.ValueForViewing("$Old_s1_Peek", Old_Top); PexObserve.ValueForViewing("$new_s1_Peek", New_Top); PexObserve.ValueForViewing("$New_ret", New_Ret); PexObserve.ValueForViewing("$New_ContainsNewRet", New_ContainsNewRet); Assert.True(((New_Ret == Old_Top && New_s1Count == -1 + Old_s1Count && (!(New_ContainsNewRet)) && Old_s1Count >= 1) || (New_Ret == Old_Top && New_s1Count == -1 + Old_s1Count && New_s1Count >= 1))); }
public void PUT_GetContract([PexAssumeUnderTest] Dictionary.Dictionary <int, int> d, int x) { AssumePrecondition.IsTrue(d.ContainsKey(x)); int Old_dCount = d.Count; int Old_x = x; bool Old_dContainsKeyX = d.ContainsKey(x); int New_Ret = d[x]; int New_dCount = d.Count; int New_x = x; bool New_dContainsKeyX = d.ContainsKey(x); PexObserve.ValueForViewing("$old_d_Count", Old_dCount); PexObserve.ValueForViewing("$new_d_Count", New_dCount); PexObserve.ValueForViewing("$old_d_x", Old_x); PexObserve.ValueForViewing("$new_d_x", New_x); PexObserve.ValueForViewing("$New_ret", New_Ret); PexObserve.ValueForViewing("$old_d_contains_key_x", Old_dContainsKeyX); PexObserve.ValueForViewing("$new_d_contains_key_x", New_dContainsKeyX); Assert.IsTrue((Old_dContainsKeyX && New_dContainsKeyX && New_dCount == Old_dCount && New_x == Old_x)); }
public void PUT_DequeueContract([PexAssumeUnderTest] Queue.Queue <int> s1) { AssumePrecondition.IsTrue(s1.Count > 0); int Old_s1Count = s1.Count; int Old_Top = s1.Peek(); /*code*/ int New_Ret = s1.Dequeue(); int New_Top = s1.Count > 0 ? s1.Peek() : PexChoose.Value <int>("new_top"); //int New_Top = s1.Count > 0 ? s1.Peek() : Old_Top - 1; // New_Top = Old_Top = OldTop - 1 int New_s1Count = s1.Count; bool New_s1ContainsNewRet = s1.Contains(New_Ret); PexObserve.ValueForViewing("$Old_s1_Count", Old_s1Count); PexObserve.ValueForViewing("$New_s1_Count", New_s1Count); PexObserve.ValueForViewing("$Old_s1_Peek", Old_Top); PexObserve.ValueForViewing("$new_s1_Peek", New_Top); PexObserve.ValueForViewing("$New_ret", New_Ret); PexObserve.ValueForViewing("$New_s1ContainsNewRet", New_s1ContainsNewRet); Assert.True(((New_s1Count == -1 + Old_s1Count && New_Ret <= Old_Top && Old_Top <= New_Ret && (!(New_s1ContainsNewRet)) && New_s1Count >= 0) || (New_s1Count == -1 + Old_s1Count && New_Ret <= Old_Top && Old_Top <= New_Ret && New_s1Count >= 1))); }
public void PUT_ClearAdjacentEdgesContract([PexAssumeUnderTest] UndirectedGraph.UndirectedGraph <int, Edge <int> > ug, int x) { AssumePrecondition.IsTrue(ug.ContainsVertex(x)); int Old_ugVertexCount = ug.VertexCount; int Old_ugEdgeCount = ug.EdgeCount; int Old_ugAdjacentDegree = ug.AdjacentDegree(x); int Old_x = x; bool Old_ugAllowParallelEdges = ug.AllowParallelEdges; bool Old_ugContainsVertexX = ug.ContainsVertex(x); //code ug.ClearAdjacentEdges(x); int New_ugVertexCount = ug.VertexCount; int New_ugEdgeCount = ug.EdgeCount; int New_ugAdjacentDegree = ug.AdjacentDegree(x); int New_x = x; bool New_ugAllowParallelEdges = ug.AllowParallelEdges; bool New_ugContainsVertexX = ug.ContainsVertex(x); PexObserve.ValueForViewing("$old_ug_vertex_count", Old_ugVertexCount); PexObserve.ValueForViewing("$new_ug_vertex_count", New_ugVertexCount); PexObserve.ValueForViewing("$old_ug_edge_count", Old_ugEdgeCount); PexObserve.ValueForViewing("$new_ug_edge_count", New_ugEdgeCount); PexObserve.ValueForViewing("$old_ug_adjacent_degree", Old_ugAdjacentDegree); PexObserve.ValueForViewing("$new_ug_adjacent_degree", New_ugAdjacentDegree); PexObserve.ValueForViewing("$old_ug_x", Old_x); PexObserve.ValueForViewing("$new_ug_x", New_x); PexObserve.ValueForViewing("$old_ug_contains_x", Old_ugContainsVertexX); PexObserve.ValueForViewing("$new_ug_contains_x", New_ugContainsVertexX); PexObserve.ValueForViewing("$old_ug_allow_parallel_edges", Old_ugAllowParallelEdges); PexObserve.ValueForViewing("$new_ug_allow_parallel_edges", New_ugAllowParallelEdges); PexAssert.IsTrue(((!(New_ugVertexCount == New_x)) && (Old_ugEdgeCount == New_ugAdjacentDegree) && (Old_x == New_x) && (New_x == 0) && (New_ugVertexCount == Old_ugVertexCount) && (New_ugAdjacentDegree == Old_ugAdjacentDegree) && (New_ugEdgeCount == 0) && (Old_ugContainsVertexX) && (New_ugContainsVertexX) && (New_ugEdgeCount == New_ugAdjacentDegree) && (Old_ugAllowParallelEdges) && (New_ugAllowParallelEdges)) || ((!(New_ugVertexCount == New_ugAdjacentDegree)) && (!(New_ugVertexCount == New_x)) && (Old_ugEdgeCount == New_ugAdjacentDegree) && (Old_x == New_x) && (New_x == 0) && (New_ugVertexCount == Old_ugVertexCount) && (New_ugAdjacentDegree == Old_ugAdjacentDegree) && (New_ugEdgeCount == 0) && (Old_ugContainsVertexX) && (!(Old_ugAllowParallelEdges)) && (New_ugContainsVertexX) && (!(New_ugAllowParallelEdges)))); }
public void PUT_PeekContract([PexAssumeUnderTest] Stack.Stack <int> s1) { AssumePrecondition.IsTrue(s1.Count > 0); int Old_s1Count = s1.Count; //int Old_Ret = PexChoose.Value<int>("old_ret"); int Old_Top = s1.Peek(); /*Code */ int New_Ret = s1.Peek(); int New_s1Count = s1.Count; int New_Top = s1.Peek(); bool New_ContainsNewRet = s1.Contains(New_Ret); PexObserve.ValueForViewing("$old_s1_Count", Old_s1Count); PexObserve.ValueForViewing("$new_s1_Count", New_s1Count); PexObserve.ValueForViewing("$old_s1_Peek", Old_Top); PexObserve.ValueForViewing("$new_s1_Peek", New_Top); //PexObserve.ValueForViewing("$old_s1_ret", Old_Ret); PexObserve.ValueForViewing("$new_ret", New_Ret); PexObserve.ValueForViewing("$New_ContainsNewRet", New_ContainsNewRet); Assert.True(((New_ContainsNewRet && New_s1Count == Old_s1Count && New_Ret == Old_Top && New_Ret == New_Top))); }
public void PUT_RemoveMinimumContract([PexAssumeUnderTest] BinaryHeap.BinaryHeap <int, int> bh) { AssumePrecondition.IsTrue(bh.Count > 0); int Old_bhCount = bh.Count; int Old_bhCapacity = bh.Capacity; int Old_bhMinimumKey = bh.Count > 0 ? bh.Minimum().Key : PexChoose.Value <int>("old_bhMinimumKey"); int Old_bhMinimumValue = bh.Count > 0 ? bh.Minimum().Value : PexChoose.Value <int>("old_bhMinimumValue"); int Old_Ret_Key = PexChoose.Value <int>("old_Ret_Key"); int Old_Ret_Value = PexChoose.Value <int>("old_Ret_Value"); //code var rm = bh.RemoveMinimum(); int New_Ret_Key = rm.Key; int New_Ret_Value = rm.Value; int New_bhCount = bh.Count; int New_bhCapacity = bh.Capacity; int New_bhMinimumKey = bh.Count > 0 ? bh.Minimum().Key : PexChoose.Value <int>("new_bhMinimumKey"); int New_bhMinimumValue = bh.Count > 0 ? bh.Minimum().Value : PexChoose.Value <int>("new_bhMinimumValue"); PexObserve.ValueForViewing("$old_bh_count", Old_bhCount); PexObserve.ValueForViewing("$new_bh_count", New_bhCount); PexObserve.ValueForViewing("$old_bh_capacity", Old_bhCapacity); PexObserve.ValueForViewing("$new_bh_capacity", New_bhCapacity); PexObserve.ValueForViewing("$old_bh_minimum_key", Old_bhMinimumKey); PexObserve.ValueForViewing("$new_bh_minimum_key", New_bhMinimumKey); PexObserve.ValueForViewing("$old_bh_minimum_value", Old_bhMinimumValue); PexObserve.ValueForViewing("$new_bh_minimum_value", New_bhMinimumValue); PexObserve.ValueForViewing("$old_ret_key", Old_Ret_Key); PexObserve.ValueForViewing("$new_ret_key", New_Ret_Key); PexObserve.ValueForViewing("$old_ret_value", Old_Ret_Value); PexObserve.ValueForViewing("$new_ret_value", New_Ret_Value); PexAssert.IsTrue(false); }
public static void Check([PexAssumeNotNull] int[] arr1, [PexAssumeNotNull] int[] arr2, [PexAssumeNotNull] int[] arr3, [PexAssumeNotNull] int[] solnArr) { PexAssume.AreDistinctReferences(new Object[] { arr1, arr2, arr3, solnArr }); //Don't refer to same mem locations PexAssume.IsTrue(isEquals(arr1, arr2)); //Deep check PexAssume.IsTrue(isEquals(arr2, arr3)); PexAssume.IsTrue(isEquals(arr3, solnArr)); bool ans1Except = false, ans2Except = false, ans3Except = false, solnExcept = false; int ans1 = -100, ans2 = -100, ans3 = -100, solnAns = -100, count = 0; try { ans1 = Partitioner.partition(arr1); } catch (IndexOutOfRangeException) { ans1Except = true; } /* * try * { * ans2 = PartitionerSub2.partition(arr2); * } * catch (IndexOutOfRangeException) * { * ans2Except = true; * } * * try * { * ans3 = PartitionerSub3.partition(arr3); * } * catch (IndexOutOfRangeException) * { * ans3Except = true; * } * */ try { solnAns = PartitionerSolutionForReal.partition(solnArr); } catch (IndexOutOfRangeException) { solnExcept = true; } bool passingCondition = ((ans1Except == solnExcept && ans1Except == true) || (ans1Except == solnExcept && ans1Except == false && ans1 == solnAns)); bool failingCondition = !passingCondition; if (failingCondition) { count++; Debug.WriteLine("sub1 not equal to instructor soln"); } /* * bool passingCondition2 = ((ans2Except == solnExcept && ans2Except == true) || (ans2Except == solnExcept && ans2Except == false && ans2 == solnAns)); * bool failingCondition2 = !passingCondition2; * if (failingCondition2) * { * count++; * Debug.WriteLine("sub2 not equal to instructor soln"); * } * * bool passingCondition3 = ((ans3Except == solnExcept && ans3Except == true) || (ans3Except == solnExcept && ans3Except == false && ans3 == solnAns)); * bool failingCondition3 = !passingCondition3; * if (failingCondition3) * { * count++; * Debug.WriteLine("sub3 not equal to instructor soln"); * } * */ PexObserve.ValueForViewing("count", count); PexAssert.IsTrue(count <= 3); }
public static void Check([PexAssumeNotNull] MetaProgram.List l, int x, Boolean b) { bool firstNull = false; bool secondNull = false; List l2 = l.Clone(); List l3 = l.Clone(); bool notSubsumption = true; try { l.addToEnd(x); } catch (NullReferenceException) { firstNull = true; } try { l2.addToEndSolution(x); } catch (NullReferenceException) { secondNull = true; } try { l3.addToEndSolutionForReal(x); } catch (NullReferenceException) { Console.WriteLine("addToEndSolutionForReal got null refence exception!"); } bool passingCondition = ((firstNull == secondNull && firstNull == true) || (firstNull == secondNull && firstNull == false && l2.isEquals(l))); bool failingCondition = !passingCondition; if (failingCondition) { throw new Exception("Student submission is equivalent to correct solution, but is not equal to reference submission."); } //Implement Subsumption PUT //Purpose: Determine if subsumption exists across submissions in different child... //...clusters within same parent cluster if (passingCondition) { if (b) { //s1 >= s2 if (l3.isEquals(l)) { if (!l2.isEquals(l)) { throw new Exception("Student submission is equivalent to correct solution, but is not equal to reference submission."); } } } else { //s2 >= s1 if (!l3.isEquals(l)) { if (l3.isEquals(l2)) { notSubsumption = false; } } } } //Visualize the val of notSubsumption PexObserve.ValueForViewing("notSubsumption", notSubsumption); PexAssert.IsTrue(notSubsumption); }
public static void Check([PexAssumeNotNull] int[] arr, Boolean b) { int[] solArr = Program.Copy(arr); int[] realSolArr = Program.Copy(arr); bool firstIndex = false; bool secondIndex = false; int[] firstArr = new int[arr.Length]; int[] secondArr = new int[arr.Length]; int[] thirdArr = new int[arr.Length]; bool notSubsumption = true; try { firstArr = Program.sort(arr); //firstArr = Program.sortSolution(arr); } catch (IndexOutOfRangeException e) { firstIndex = true; } try { secondArr = Program.sortSolution(solArr); } catch (IndexOutOfRangeException e) { secondIndex = true; } try { thirdArr = Program.sortSolutionForReal(realSolArr); } catch (IndexOutOfRangeException e) { Console.WriteLine("sortSolutionForReal got index out of range!"); } bool passingCondition = ((firstIndex == secondIndex && firstIndex == true) || (firstIndex == secondIndex && firstIndex == false && Program.isEquals(firstArr, secondArr))); bool failingCondition = !passingCondition; if (failingCondition) { throw new Exception("Failed test: Reference solution not equal to student submission."); } if (passingCondition) { if (b) { //s1 >= s2 if (Program.isEquals(thirdArr, firstArr)) { if (!Program.isEquals(secondArr, firstArr)) { throw new Exception("Student submission is equivalent to correct solution, but is not equal to reference submission."); } } } else { //s2 >= s1 if (!Program.isEquals(thirdArr, firstArr)) { if (Program.isEquals(thirdArr, secondArr)) { notSubsumption = false; } } } } //Visualize the val of notSubsumption PexObserve.ValueForViewing("notSubsumption", notSubsumption); PexAssert.IsTrue(notSubsumption); }
public static void Check([PexAssumeNotNull] int[] arr, Boolean b) { /* * This problem ask students to solve a static method so we don't require cloning or implementing * an isEquals method for a class because static method don't require object instances in order to be called. */ bool firstIndex = false; bool secondIndex = false; bool output = false; bool outputSolution = false; bool outputForRealSolution = false; bool notSubsumption = true; try { output = Program.isSorted(arr); } catch (IndexOutOfRangeException) { firstIndex = true; } try { outputSolution = Program.isSortedSolution(arr); } catch (IndexOutOfRangeException) { secondIndex = true; } try { outputForRealSolution = Program.isSortedSolutionForReal(arr); } catch (IndexOutOfRangeException) { Console.WriteLine("isSortedSolutionForReal got index out of range!"); } //program passes under these scenarios // (1)both throw exception so firstIndex == secondIndex but since the programs don't terminate //and exit abnormally (exception), the the outputs are unchanged, outputSolution == output //(2) neither program fails (firstIndex == secondIndex), and must agree on output (outputSolution == output). bool passingCondition = (firstIndex == secondIndex && firstIndex == true) || (firstIndex == secondIndex && firstIndex == false && (outputSolution == output)); /*negation of passing condition*/ bool failingCondition = !passingCondition; if (failingCondition) { throw new Exception("Failed test: Reference solution not equal to student submission."); } //Implement Subsumption PUT //Purpose: Determine if subsumption exists across submissions in different child... //...clusters within same parent cluster //if (passingCondition == true && firstIndex == false) if (passingCondition) { if (b) { //s1 >= s2 if (outputForRealSolution == output) { if (outputSolution != output) { throw new Exception("Student submission is equivalent to correct solution, but is not equal to reference submission."); } } } else { //s2 >= s1 if (outputForRealSolution != output) { if (outputForRealSolution == outputSolution) { notSubsumption = false; } } } } //Visualize the val of notSubsumption PexObserve.ValueForViewing("notSubsumption", notSubsumption); PexAssert.IsTrue(notSubsumption); }
public void MinHeapPUT([PexAssumeNotNull] List <int> input) { Heap <int> actual = new Heap <int>(input, Strategy.Min); PexObserve.ValueForViewing <int[]>("Actual", actual.ToArray()); }
public static void Check([PexAssumeUnderTest] MetaProgram.List l, [PexAssumeUnderTest] MetaProgram.List l4, [PexAssumeUnderTest] MetaProgram.List l6, [PexAssumeUnderTest] MetaProgram.List l9, [PexAssumeUnderTest] MetaProgram.List l10, [PexAssumeUnderTest] MetaProgram.List lSoln, int x) { /*PexAssume.IsTrue(MetaProgram.List.Equals(l, l4)); * PexAssume.IsTrue(MetaProgram.List.Equals(l4, l6)); * PexAssume.IsTrue(MetaProgram.List.Equals(l6, l9)); * PexAssume.IsTrue(MetaProgram.List.Equals(l9, l10)); * PexAssume.IsTrue(MetaProgram.List.Equals(l10, lSoln));*/ //PexAssume.AreDistinctReferences(new Object[] { l, l4, l6, l9, l10, lSoln }); PexAssume.IsTrue(MetaProgram.List.Equals(l9, lSoln)); PexAssume.AreDistinctReferences(new Object[] { l9, lSoln }); bool firstNull = false; bool fourNull = false; bool sixNull = false; bool nineNull = false; bool tenNull = false; bool solnNull = false; int count = 0; /* * try * { * l.addToEnd(x); * } * catch (NullReferenceException) * { * firstNull = true; * } * * * * try * { * l4.addToEnd4(x); * } * catch (NullReferenceException) * { * fourNull = true; * } * * * * * try * { * l6.addToEnd6(x); * } * catch (NullReferenceException) * { * sixNull = true; * } * */ try { l9.addToEnd9(x); } catch (NullReferenceException) { nineNull = true; } /* * try * { * l10.addToEnd10(x); * } * catch (NullReferenceException) * { * tenNull = true; * } * */ try { lSoln.addToEndSolutionForReal(x); } catch (NullReferenceException) { solnNull = true; } /* * bool passingCondition1 = ((firstNull == solnNull && firstNull == true) || (firstNull == solnNull && firstNull == false && MetaProgram.List.Equals(l, lSoln))); * bool failingCondition1 = !passingCondition1; * if (failingCondition1) * { * count++; * Console.WriteLine("sub1 not equal to instructor soln"); * } * * * * bool passingCondition4 = ((fourNull == solnNull && fourNull == true) || (fourNull == solnNull && fourNull == false && MetaProgram.List.Equals(l4, lSoln))); * bool failingCondition4 = !passingCondition4; * if (failingCondition4) * { * count++; * Console.WriteLine("sub4 not equal to instructor soln"); * } * * * * bool passingCondition6 = ((sixNull == solnNull && sixNull == true) || (sixNull == solnNull && sixNull == false && MetaProgram.List.Equals(l6, lSoln))); * bool failingCondition6 = !passingCondition6; * if (failingCondition6) * { * count++; * Console.WriteLine("sub6 not equal to instructor soln"); * } * */ bool passingCondition9 = ((nineNull == solnNull && nineNull == true) || (nineNull == solnNull && nineNull == false && MetaProgram.List.Equals(l9, lSoln))); bool failingCondition9 = !passingCondition9; if (failingCondition9) { count++; Console.WriteLine("sub9 not equal to instructor soln"); } /* * bool passingCondition10 = ((tenNull == solnNull && tenNull == true) || (tenNull == solnNull && tenNull == false && MetaProgram.List.Equals(l10, lSoln))); * bool failingCondition10 = !passingCondition10; * if (failingCondition10) * { * count++; * Debug.WriteLine("sub10 not equal to instructor soln"); * } */ PexObserve.ValueForViewing("count", count); PexAssert.IsTrue(count == 1); //<------ SUBJECT TO CHANGE!!!! }