public void SetUp() { mockery = new Mockery(); mockStreamReader = mockery.NewMock <IStreamReader>(); allWordsTrieRoot = new Dictionary <Char, TrieNode <Char> >(); allWords = new HashSet <String>(); fromCharacterFrequencies = new FrequencyTable <Char>(); characterSubstitutionFrequencies = new FrequencyTable <CharacterSubstitution>(); List <String> testWords = new List <String>() { "read", "bead", "fail", "dead", "road", "reed", "calm", "real", "rear" }; Func <String, Boolean> wordFilterFunction = new Func <String, Boolean>((inputString) => { return(true); }); CharacterTrieBuilder characterTrieBuilder = new CharacterTrieBuilder(); using (mockery.Ordered) { foreach (String currentTestWord in testWords) { Expect.Once.On(mockStreamReader).GetProperty("EndOfStream").Will(Return.Value(false)); Expect.Once.On(mockStreamReader).Method("ReadLine").WithNoArguments().Will(Return.Value(currentTestWord)); } Expect.Once.On(mockStreamReader).GetProperty("EndOfStream").Will(Return.Value(true)); Expect.Once.On(mockStreamReader).Method("Dispose").WithNoArguments(); } dataStructureUtilities.PopulateAdjacentWordDataStructures(mockStreamReader, characterTrieBuilder, wordFilterFunction, allWordsTrieRoot, allWords, fromCharacterFrequencies, characterSubstitutionFrequencies); mockery.ClearExpectation(mockStreamReader); testCandidateWordPriorityCalculator = new CandidateWordPriorityCalculator(20, 1, 1, 1, 1, allWordsTrieRoot, fromCharacterFrequencies, characterSubstitutionFrequencies); }
public void Insert() { Int32[] elementList = new Int32[] { 0 }; using (mockery.Ordered) { Expect.Once.On(mockBinarySearchTree).Method("Clear").WithNoArguments(); Expect.Once.On(mockBinarySearchTree).Method("Add").With(0); } testBinarySearchTreeBalancedInserter.Insert(mockBinarySearchTree, elementList); mockery.VerifyAllExpectationsHaveBeenMet(); elementList = new Int32[] { 0, 1 }; mockery.ClearExpectation(mockBinarySearchTree); using (mockery.Ordered) { Expect.Once.On(mockBinarySearchTree).Method("Clear").WithNoArguments(); Expect.Once.On(mockBinarySearchTree).Method("Add").With(1); Expect.Once.On(mockBinarySearchTree).Method("Add").With(0); } testBinarySearchTreeBalancedInserter.Insert(mockBinarySearchTree, elementList); mockery.VerifyAllExpectationsHaveBeenMet(); elementList = new Int32[] { 0, 1, 2 }; mockery.ClearExpectation(mockBinarySearchTree); using (mockery.Ordered) { Expect.Once.On(mockBinarySearchTree).Method("Clear").WithNoArguments(); Expect.Once.On(mockBinarySearchTree).Method("Add").With(1); Expect.Once.On(mockBinarySearchTree).Method("Add").With(0); Expect.Once.On(mockBinarySearchTree).Method("Add").With(2); } testBinarySearchTreeBalancedInserter.Insert(mockBinarySearchTree, elementList); mockery.VerifyAllExpectationsHaveBeenMet(); elementList = new Int32[] { 0, 1, 2, 3 }; mockery.ClearExpectation(mockBinarySearchTree); using (mockery.Ordered) { Expect.Once.On(mockBinarySearchTree).Method("Clear").WithNoArguments(); Expect.Once.On(mockBinarySearchTree).Method("Add").With(2); Expect.Once.On(mockBinarySearchTree).Method("Add").With(1); Expect.Once.On(mockBinarySearchTree).Method("Add").With(0); Expect.Once.On(mockBinarySearchTree).Method("Add").With(3); } testBinarySearchTreeBalancedInserter.Insert(mockBinarySearchTree, elementList); mockery.VerifyAllExpectationsHaveBeenMet(); elementList = new Int32[] { 0, 1, 2, 3, 4 }; mockery.ClearExpectation(mockBinarySearchTree); using (mockery.Ordered) { Expect.Once.On(mockBinarySearchTree).Method("Clear").WithNoArguments(); Expect.Once.On(mockBinarySearchTree).Method("Add").With(2); Expect.Once.On(mockBinarySearchTree).Method("Add").With(1); Expect.Once.On(mockBinarySearchTree).Method("Add").With(0); Expect.Once.On(mockBinarySearchTree).Method("Add").With(4); Expect.Once.On(mockBinarySearchTree).Method("Add").With(3); } testBinarySearchTreeBalancedInserter.Insert(mockBinarySearchTree, elementList); mockery.VerifyAllExpectationsHaveBeenMet(); }
public void Generate() { IRandomIntegerGenerator mockRandomIntegerGenerator = mockery.NewMock <IRandomIntegerGenerator>(); testWeightedRandomGenerator = new WeightedRandomGenerator <Char>(mockRandomIntegerGenerator); // Test with a single weighting of 1 using (mockery.Ordered) { Expect.Once.On(mockRandomIntegerGenerator).Method("Next").With(1L).Will(Return.Value(0L)); } testWeightedRandomGenerator.SetWeightings(new List <Tuple <Char, Int64> >() { new Tuple <Char, Int64>('a', 1) }); Char result = testWeightedRandomGenerator.Generate(); Assert.AreEqual('a', result); mockery.VerifyAllExpectationsHaveBeenMet(); // Test with 2 weightings, first a single value of 1, and the second the entire remaining space in the (Int64.MaxValue - 1) range mockery.ClearExpectation(mockRandomIntegerGenerator); List <Tuple <Char, Int64> > weightings = new List <Tuple <Char, Int64> > { new Tuple <Char, Int64>('a', 1), new Tuple <Char, Int64>('b', Int64.MaxValue - 1) }; using (mockery.Ordered) { Expect.Once.On(mockRandomIntegerGenerator).Method("Next").With(Int64.MaxValue).Will(Return.Value(0L)); Expect.Once.On(mockRandomIntegerGenerator).Method("Next").With(Int64.MaxValue).Will(Return.Value(1L)); Expect.Once.On(mockRandomIntegerGenerator).Method("Next").With(Int64.MaxValue).Will(Return.Value(Int64.MaxValue - 1)); } testWeightedRandomGenerator.SetWeightings(weightings); result = testWeightedRandomGenerator.Generate(); Assert.AreEqual('a', result); result = testWeightedRandomGenerator.Generate(); Assert.AreEqual('b', result); result = testWeightedRandomGenerator.Generate(); Assert.AreEqual('b', result); mockery.VerifyAllExpectationsHaveBeenMet(); // Test with 2 weightings, first with (Int64.MaxValue - 1) range, and the second with 1 mockery.ClearExpectation(mockRandomIntegerGenerator); weightings = new List <Tuple <Char, Int64> > { new Tuple <Char, Int64>('a', Int64.MaxValue - 1), new Tuple <Char, Int64>('b', 1) }; using (mockery.Ordered) { Expect.Once.On(mockRandomIntegerGenerator).Method("Next").With(Int64.MaxValue).Will(Return.Value(0L)); Expect.Once.On(mockRandomIntegerGenerator).Method("Next").With(Int64.MaxValue).Will(Return.Value(Int64.MaxValue - 2)); Expect.Once.On(mockRandomIntegerGenerator).Method("Next").With(Int64.MaxValue).Will(Return.Value(Int64.MaxValue - 1)); } testWeightedRandomGenerator.SetWeightings(weightings); result = testWeightedRandomGenerator.Generate(); Assert.AreEqual('a', result); result = testWeightedRandomGenerator.Generate(); Assert.AreEqual('a', result); result = testWeightedRandomGenerator.Generate(); Assert.AreEqual('b', result); mockery.VerifyAllExpectationsHaveBeenMet(); // Test with more standard weightings mockery.ClearExpectation(mockRandomIntegerGenerator); weightings = new List <Tuple <Char, Int64> > { new Tuple <Char, Int64>('a', 1), new Tuple <Char, Int64>('b', 2), new Tuple <Char, Int64>('c', 4) }; using (mockery.Ordered) { Expect.Once.On(mockRandomIntegerGenerator).Method("Next").With(7L).Will(Return.Value(0L)); Expect.Once.On(mockRandomIntegerGenerator).Method("Next").With(7L).Will(Return.Value(1L)); Expect.Once.On(mockRandomIntegerGenerator).Method("Next").With(7L).Will(Return.Value(2L)); Expect.Once.On(mockRandomIntegerGenerator).Method("Next").With(7L).Will(Return.Value(3L)); Expect.Once.On(mockRandomIntegerGenerator).Method("Next").With(7L).Will(Return.Value(4L)); Expect.Once.On(mockRandomIntegerGenerator).Method("Next").With(7L).Will(Return.Value(5L)); Expect.Once.On(mockRandomIntegerGenerator).Method("Next").With(7L).Will(Return.Value(6L)); } testWeightedRandomGenerator.SetWeightings(weightings); result = testWeightedRandomGenerator.Generate(); Assert.AreEqual('a', result); result = testWeightedRandomGenerator.Generate(); Assert.AreEqual('b', result); result = testWeightedRandomGenerator.Generate(); Assert.AreEqual('b', result); result = testWeightedRandomGenerator.Generate(); Assert.AreEqual('c', result); result = testWeightedRandomGenerator.Generate(); Assert.AreEqual('c', result); result = testWeightedRandomGenerator.Generate(); Assert.AreEqual('c', result); result = testWeightedRandomGenerator.Generate(); Assert.AreEqual('c', result); mockery.VerifyAllExpectationsHaveBeenMet(); }