public static MetaProject.BinaryTreeSolution CreateBinaryTreeSolution([PexAssumeNotNull] double[] arr) { MetaProject.BinaryTreeSolution tree = new MetaProject.BinaryTreeSolution(); for (int i = 0; i < arr.Length; i++) { tree.add(arr[i]); } return(tree); }
public static void Check([PexAssumeUnderTest] BinaryTree tree1, [PexAssumeUnderTest] BinaryTreeSolution tree2, double x, string inputString, bool treeType, int numIterations) { //Assume both trees have same contents PexAssume.IsTrue(isEqual(tree1.root, tree2.root)); //Assume both trees have same number of nodes PexAssume.IsTrue(Count(tree1.root).Equals(Count(tree2.root))); //Assume trees don't point to same mem locations PexAssume.AreNotSame(tree1, tree2); bool tree1Exception = false; bool tree2Exception = false; try { if (treeType) { for (int i = 0; i < numIterations; i++) { tree1.add(inputString); //treeType = true => input string } } else { for (int i = 0; i < numIterations; i++) { tree1.add(x); //treeType = false => input double } } } catch (Exception) { tree1Exception = true; } try { if (treeType) { for (int i = 0; i < numIterations; i++) { tree2.add(inputString); } } else { for (int i = 0; i < numIterations; i++) { tree2.add(x); } } } catch (Exception) { tree2Exception = true; } bool passingCondition = ((tree1Exception == tree2Exception && tree1Exception == true) || (tree1Exception == tree2Exception && tree1Exception == false && tree1.countLessThan(x).Equals(tree2.countLessThan(x)))); bool failingCondition = !passingCondition; if (failingCondition) { throw new Exception(); } }