public void TestRetrieveQueryableDataFileAlreadyLoaded() { //Create the mock file loader Mock <IAnswerDataJsonFileLoader> mockFileLoader = CreateMockFileLoader(); //Create an AnswerDB instance AnswerDB testAnswerDB = new AnswerDB(mockFileLoader.Object, TestDataFileName); //Retrieve the test data, which will be our expected data List <Answer> expectedAnswers = CreateTestData(); //Retrieve the Querable from the DB IQueryable <Answer> answerQueryable = testAnswerDB.GetAnswerQueryable(); //Verify that the file loader was called correctly mockFileLoader.Verify(mock => mock.LoadAnswerDataFromFile( It.Is <string>(fileName => fileName == TestDataFileName)), Times.Once); //That should have loaded the file to the DB. Retrieve the queryable again. answerQueryable = testAnswerDB.GetAnswerQueryable(); //Verify that we actually got a queryable Assert.That(answerQueryable, Is.Not.Null); //Verify that the queryable returns the correct data List <Answer> actualAnswers = answerQueryable.ToList(); expectedAnswers.Zip(actualAnswers, Tuple.Create) .ToList() .ForEach(answerTuple => DataComparers.CompareAnswers(answerTuple.Item1, answerTuple.Item2)); //Verify that the file loader was not called again mockFileLoader.Verify(mock => mock.LoadAnswerDataFromFile(It.IsAny <string>()), Times.Once); }
public void CustomData_ShouldReturnCorrectTree() { //Arrange IBinarySearchTree <int> tree = new AVLTree <int>(DataComparers.NewByType <int>()); tree = tree.AddNode(40); tree = tree.AddNode(20); tree = tree.AddNode(10); tree = tree.AddNode(25); tree = tree.AddNode(30); tree = tree.AddNode(22); tree = tree.AddNode(50); //Act Assert.Equal(25, tree.Value); Assert.Equal(3, tree.Height); Assert.Equal(20, tree.Left.Value); Assert.Equal(2, tree.Left.Height); Assert.Equal(10, tree.Left.Left.Value); Assert.Equal(1, tree.Left.Left.Height); Assert.Equal(22, tree.Left.Right.Value); Assert.Equal(1, tree.Left.Right.Height); Assert.Equal(40, tree.Right.Value); Assert.Equal(2, tree.Right.Height); Assert.Equal(30, tree.Right.Left.Value); Assert.Equal(1, tree.Right.Left.Height); Assert.Equal(50, tree.Right.Right.Value); Assert.Equal(1, tree.Right.Right.Height); }
public void LLWithSubtrees_ShouldRightRotate() { //Arrange IBinarySearchTree <int> tree = new AVLTree <int>(DataComparers.NewByType <int>()); tree = tree.AddNode(30); tree = tree.AddNode(35); tree = tree.AddNode(20); tree = tree.AddNode(25); tree = tree.AddNode(10); tree = tree.AddNode(5); //Act Assert.Equal(20, tree.Value); Assert.Equal(3, tree.Height); Assert.Equal(10, tree.Left.Value); Assert.Equal(2, tree.Left.Height); Assert.Equal(5, tree.Left.Left.Value); Assert.Equal(1, tree.Left.Left.Height); Assert.Equal(30, tree.Right.Value); Assert.Equal(2, tree.Right.Height); Assert.Equal(25, tree.Right.Left.Value); Assert.Equal(1, tree.Right.Left.Height); Assert.Equal(35, tree.Right.Right.Value); Assert.Equal(1, tree.Right.Right.Height); }
public void InOrder() { //Arrange var tree = new BinarySearchTree <int>(DataComparers.NewByType <int>()); tree.AddNode(50); tree.AddNode(20); tree.AddNode(60); tree.AddNode(30); tree.AddNode(40); tree.AddNode(55); //Act var inorder = new List <int>(); tree.InOrder((v) => inorder.Add(v.Value)); Assert.Equal(6, inorder.Count); Assert.Equal(20, inorder[0]); Assert.Equal(30, inorder[1]); Assert.Equal(40, inorder[2]); Assert.Equal(50, inorder[3]); Assert.Equal(55, inorder[4]); Assert.Equal(60, inorder[5]); }
public void TestLoadingFileWithSingleRecord() { //Define the expected data List <Answer> expectedData = new List <Answer>() { new Answer() { SubmittedAnswerId = 12345, SubmitDateTime = DateTime.Parse("2018-01-30T08:57:00.00"), Correct = 1, Progress = 0, UserId = 56789, ExerciseId = 23, Difficulty = "5", Subject = "Geschiedenis", Domain = "-", LearningObjective = "Industrial Revolution" } }; //Create the JSON file loader IAnswerDataJsonFileLoader fileLoader = new AnswerDataJsonFileLoader(); //Load the test file List <Answer> actualData = fileLoader.LoadAnswerDataFromFile(SingleAnswerFileName); //Compare the actual data to the expected data Assert.That(actualData.Count, Is.EqualTo(expectedData.Count)); expectedData.Zip(actualData, Tuple.Create) .ToList() .ForEach(dataTuple => DataComparers.CompareAnswers(dataTuple.Item1, dataTuple.Item2)); }
public void SearchExistingElement() { //Arrange var tree = new BinarySearchTree <int>(DataComparers.NewByType <int>()); var item = tree.AddNode(50); item = tree.AddNode(20); item = tree.AddNode(60); item = tree.AddNode(30); item = tree.AddNode(40); item = tree.AddNode(55); //Act var res = tree.Search(50); Assert.True(res != null); res = tree.Search(20); Assert.True(res != null); res = tree.Search(60); Assert.True(res != null); res = tree.Search(30); Assert.True(res != null); res = tree.Search(40); Assert.True(res != null); res = tree.Search(55); Assert.True(res != null); }
public void OneElement_SearchExistingElement() { //Arrange var tree = new BinarySearchTree <int>(DataComparers.NewByType <int>()); tree.AddNode(50); //Act Assert.True(tree.Search(50) != null); }
static void Main(string[] args) { var tree = new BinarySearchTree <int>(DataComparers.NewByType <int>()); tree.AddNode(50); tree.AddNode(30); tree.AddNode(60); tree.AddNode(20); tree.AddNode(40); tree.AddNode(55); var newTree = tree.Clone(); System.Console.ReadLine(); }
public void SearchNotExistingElement() { //Arrange var tree = new BinarySearchTree <int>(DataComparers.NewByType <int>()); tree.AddNode(50); tree.AddNode(20); tree.AddNode(60); tree.AddNode(30); tree.AddNode(40); tree.AddNode(55); //Act Assert.True(tree.Search(255) == null); }
/// <summary> /// Runs a student summary test with a particular test of test data /// </summary> /// <param name="testData">The set of test data to use when running the test</param> private void RunStudentSummaryTestWithData(List <Answer> testData) { //Define the target date/time when the summary is created DateTime targetDateTime = DateTime.Parse("2018-01-30T12:39:00"); //Calculate the expected daily summary DailyStudentSummary expectedSummary = CalculateExpectedSummaryData(testData, targetDateTime); //Create the mock answer DB Mock <IAnswerDB> mockAnswerDB = CreateMockAnswerDB(testData); //Create an instance of the answer repository IAnswerRepository answerRepository = new AnswerRepository(mockAnswerDB.Object); //Retrieve the daily student summary DailyStudentSummary actualSummary = answerRepository.GetDailyStudentSummary(targetDateTime); //Compare the actual summary to the expected summary to see if they match DataComparers.CompareDailyStudentSummaries(actualSummary, expectedSummary); }