public void ChangingASerializableItemShouldChangeTheContentHash(string[] items, int toChange, string newValue) { PexAssume.IsNotNullOrEmpty(items); PexAssume.TrueForAll(items, x => x != null); PexAssume.AreDistinctReferences(items); PexAssume.IsTrue(toChange >= 0 && toChange < items.Length); (new TestScheduler()).With(sched => { var fixture = new SerializedCollection <ModelTestFixture>( items.Select(x => new ModelTestFixture() { TestString = x })); bool shouldDie = true; var hashBefore = fixture.ContentHash; PexAssume.AreNotEqual(newValue, fixture[toChange].TestString); fixture.Changed.Subscribe(_ => shouldDie = false); Observable.Return(newValue, sched).Subscribe(x => fixture[toChange].TestString = x); sched.Start(); PexAssert.AreNotEqual(hashBefore, fixture.ContentHash); PexAssert.IsFalse(shouldDie); }); }
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!!!! }
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); }