예제 #1
0
        public void BookCalculatesAnAverageGrade()
        {
            /*
             * Three Sections
             * 1. Arrange
             * 2. Act
             * 3. Assert
             */

            //Arrange
            var book = new InMemoryBook("");

            book.AddGrade(89.1);
            book.AddGrade(90.5);
            book.AddGrade(77.3);


            //Act
            var result = book.GetStatistics();

            //Assert API and Assert
            Assert.Equal(85.6, result.Average, 1);
            Assert.Equal(90.5, result.High, 1);
            Assert.Equal(77.3, result.Low, 1);
            Assert.Equal('B', result.Letter);
        }
예제 #2
0
        public void BookCalcutesAnAverageGrade()
        {
            //People usually break up unit tests into 3 sections (the tripple A testing sections)
            //1st Section:
            //Arrange (gather test data and arrange objects and values that you will use)

            //If you are referencing classes that are in other folders you can add a ProjectReference.
            //can add a ProjectReference by typing into terminal: dotnet add reference ../../src/GradeBook/GradeBook.csproj
            //The above will add an ItemGroup into the csproj Tests file
            var book = new InMemoryBook("");

            book.AddGrade(89.1);
            book.AddGrade(90.5);
            book.AddGrade(77.3);

            //2nd Section:
            //Act (invoke a method to perform a computation. Do something to check actual result)
            var result = book.GetStatistics();

            //3rd Section:
            //Assert (assert something about the value found in Act)
            //When you use Assert.Equal you can pass 2 or 3 parameters into this test
            //the firest is the expected result
            //the second is running the actual test
            //the third is "precision" where you can say to how many decimal places you would like to check
            Assert.Equal(85.6, result.Average, 1);
            Assert.Equal(90.5, result.High, 1);
            Assert.Equal(77.3, result.Low, 1);
            Assert.Equal('B', result.Letter);
        }
        public void GradesMustBeBetweenZeroAndOneHundred()
        {
            var book   = new InMemoryBook("");
            var grades = new List <double>(3)
            {
                -10, 200, 90
            };

            foreach (double grade in grades)
            {
                try
                {
                    book.AddGrade(grade);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            var stats = book.GetStatistics();

            Assert.Equal(90.0, stats.Average, 1);
            Assert.Equal(90.0, stats.High, 1);
            Assert.Equal(90.0, stats.Low, 1);
        }
예제 #4
0
        public void TestAverage()
        {
            //Arrange
            IBook book   = new InMemoryBook("Test");
            var   grades = new List <double> {
                100.0,
                100.0,
                20.0,
                20.0,
                80.0,
                60.0,
            };

            foreach (var grade in grades)
            {
                book.AddGrade(grade);
            }
            //Act
            var stats = book.GetStatistics();

            //Assert
            Assert.Equal(20, stats.LowScore);
            Assert.Equal(100, stats.HighScore);
            Assert.Equal(63.3, stats.Average, 1);
            Console.WriteLine(stats.Letter);
            Assert.Equal('C', stats.Letter);
        }
예제 #5
0
        public void BookCalculatesStatistics()
        {
            // Arrange
            var book = new InMemoryBook("Test");

            book.AddGrade(89.1);
            book.AddGrade(90.5);
            book.AddGrade(77.3);
            // Should not add invalid grade
            try {
                book.AddGrade(105);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine("Add Grade failed as expected.");
                Console.WriteLine(ex.Message);
            }

            // Act
            var results = book.GetStatistics();

            // Assert
            Assert.Equal(85.6, results.Average, 1);
            Assert.Equal(90.5, results.Highest, 1);
            Assert.Equal(77.3, results.Lowest, 1);
            Assert.Equal('B', results.Letter);
        }
예제 #6
0
        public void CheckGradeBounds()
        {
            InMemoryBook book;
            Statistics   stats;

            book = new InMemoryBook("Test Book");

            book.AddGrade(32);
            book.AddGrade(0);
            try
            {
                book.AddGrade(-10);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.ToString());
            }

            book.AddGrade(64);
            book.AddGrade(100);
            try
            {
                book.AddGrade(110);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.ToString());
            }

            stats = book.GetStatistics();

            Assert.Equal(0, stats.Minimum);
            Assert.Equal(100, stats.Maximum);
        }
예제 #7
0
        [Fact]    //attribute 
        public void BookCalculatesAnAverageGrade()
        {


            //arrange
            var book =  new InMemoryBook("");
             book.AddGrade(45.23);
             book.AddGrade(13.69);
             book.AddGrade(36.12);
             book.AddGrade(99.32);
            
             


            //act 

            var result= book.GetStatistics();


            //assert
          
            Assert.Equal(48.6,result.Average,1);
            Assert.Equal(99.3,result.High,1);
            Assert.Equal(13.7,result.Low,1);
           

        }
예제 #8
0
        public void BookCalculatesAnAverageGrades()
        {
            // arrange
            var book = new InMemoryBook("Arthur's Grade Book");


            for (int i = 0; i > 20; i++)
            {
                var input = Console.ReadLine();
                var grade = double.Parse(input);

                if (input == "q")
                {
                    i = 21;
                }
            }

            // act
            var result = book.GetStatistics();

            // assert
            Assert.Equal(85.6, result.Average, 1);
            Assert.Equal(90.5, result.High, 1);
            Assert.Equal(77.3, result.Low, 1);
            Assert.Equal('B', result.Letter);
        }
예제 #9
0
        public void CorrectListGradesAreAdded()
        {
            //* Arrange *//
            var book = new InMemoryBook("Test Book");

            //* Act *//
            // Double
            book.AddGrades(new List <double>()
            {
                -0.0, 0.0, 100.0
            });
            // Int
            book.AddGrades(new List <int>()
            {
                -0, 0, 100
            });
            // String
            book.AddGrades(new List <string>()
            {
                "-0.0", "0.0", "100.0"
            });
            book.AddGrades(new List <string>()
            {
                "-0.0", "0", "100.0"
            });
            // Letters
            book.AddGrades(new List <char>()
            {
                'a', 'b', 'c', 'A', 'B', 'C'
            });

            //* Assert *//
            Assert.Equal(18, book.Grades.Count);
            Assert.Equal(48.9, book.GetStatistics().Average, 1);
        }
예제 #10
0
        public void BookCalculateAnAverageGrade()
        {
            // arrange

            /*
             * var x = 5;
             * var y = 2;
             * var expected = 7;
             */
            var book = new InMemoryBook("");

            book.AddGrade(89.1);
            book.AddGrade(90.5);
            book.AddGrade(77.3);



            // act
            // var actual = x * y;// failure
            // var actual = x + y;//  pass
            var result = book.GetStatistics();


            // assert
            //Assert.Equal(expected, actual);
            Assert.Equal(85.6, result.Average, 1);
            Assert.Equal(90.5, result.High, 1);
            Assert.Equal(77.3, result.Low, 1);
            Assert.Equal('B', result.Letter);
        }
예제 #11
0
        public void OutAddGrade_Number_ReturnsThatNumber()
        {
            var book = new InMemoryBook("0");

            OutAddGrade(out book, 1, "1");
            var result = book.GetStatistics();

            Assert.Equal(1, result.Average);
        }
예제 #12
0
        public void AddGrade_InvalidGrade_ReturnsNaN(double input)
        {
            InMemoryBook book = new InMemoryBook("0");

            book.AddGrade(input);
            var result = book.GetStatistics();

            Assert.True(double.IsNaN(result.Average));
        }
예제 #13
0
        public void CannotAddGreaterGrade()
        {
            InMemoryBook book1 = GetBook("Book 1");

            book1.AddGrade(105);
            var x = book1.GetStatistics();

            Assert.NotEqual(x.High, 105);
        }
예제 #14
0
        public void GradeNotAddedIfGreaterThanOneHundred()
        {
            var book = new InMemoryBook("");

            book.AddGrade(101);

            var result = book.GetStatistics();

            Assert.Equal(Double.NaN, result.Average);
        }
예제 #15
0
        public void GradeNotAddedIfLessThanZero()
        {
            var book = new InMemoryBook("");

            book.AddGrade(-1);

            var result = book.GetStatistics();

            Assert.Equal(Double.NaN, result.Average);
        }
예제 #16
0
        public void StatisticsShownCorrectlyOnEmptyStats()
        {
            var book = new InMemoryBook("Empty Statistics");

            var result = book.GetStatistics();

            Assert.Equal(0, result.Low);
            Assert.Equal(0, result.High);
            Assert.Equal(0, result.Average);
        }
예제 #17
0
        public void AddOnlyValidGradeRange()
        {
            var book = new InMemoryBook("Book Test");

            book.AddGrade(5.1);

            var result = book.GetStatistics();

            Assert.AreEqual(5.1, result.High);
        }
예제 #18
0
        public void Test1()
        {
            var book1 = new InMemoryBook("Rodo");

            book1.AddGrade(90);
            book1.AddGrade(100);

            var stats = book1.GetStatistics();

            Assert.Equal(100, stats.High);
        }
예제 #19
0
        public void BookCalculateLetterGrade()
        {
            var book = new InMemoryBook("book 1");

            book.AddGrade(90);
            book.AddGrade(90);
            book.AddGrade(90);
            Statistics stats = book.GetStatistics();

            Assert.Equal('A', stats.LetterGrade);
        }
예제 #20
0
        public void GradeValueIsMore()
        {
            var book = new InMemoryBook("Book 1");
            //book.AddGrade(101);

            var number = book.GetStatistics();

            var result = double.MinValue;

            Assert.Equal(result, number.High);
        }
        public void RejectsInvalidGradeValue()
        {
            var book = new InMemoryBook("This Book");

            book.AddGrade(90);
            book.AddGrade(73.7);
            //book.AddGrade(102);

            var result = book.GetStatistics();

            Assert.Equal(90, result.High);
        }
예제 #22
0
        public void BookCalculatesAnAverageGrade()
        {
            var book = new InMemoryBook("Scott's book");

            book.AddGrade(89.1);
            book.AddGrade(90.5);
            book.AddGrade(77.3);

            var stats = book.GetStatistics();

            Assert.Equal(85.63, stats.Average, 2);
        }
예제 #23
0
        public void StatisticsTests()
        {
            var book = new InMemoryBook();

            book.AddGrade(89.1);
            book.AddGrade(90.5);
            book.AddGrade(77.3);

            var result = book.GetStatistics();

            Assert.Equal(85.6, result.average, 1);
        }
        public void BooksCalculateAnAverageGrade()
        {
            var book = new InMemoryBook("Pride and Prejudice");

            book.AddGrade(2.0);
            book.AddGrade(10.0);
            var average = book.GetStatistics();

            Console.WriteLine(average);

            Assert.Equal(6.0, average.Average, 1);
        }
예제 #25
0
        public void DoWhileCheck()
        {
            InMemoryBook bookCheck = new InMemoryBook("Georgie's Asshole");

            bookCheck.AddGrade(98.1);
            bookCheck.AddGrade(77.5);
            bookCheck.AddGrade(73.2);

            var result = bookCheck.GetStatistics();

            Assert.Equal(73.2, result.Low, 1);
        }
예제 #26
0
        public void BookValidatesGrade()
        {
            // arrange
            var book = new InMemoryBook("");

            // act
            var result = book.GetStatistics().Max;

            // assert
            Assert.AreEqual(double.MinValue, result);
            Assert.ThrowsException <ArgumentException>(() => book.AddGrade(105));
        }
예제 #27
0
        public void GetStatistics_MultipleNumbers_ReturnsLetterGrade(int input, char expected)
        {
            // Arrange
            InMemoryBook book = new InMemoryBook("0");

            // Act
            book.AddGrade(input);
            var result = book.GetStatistics();

            // Assert
            Assert.Equal(expected, result.Letter);
        }
예제 #28
0
        public void GetStatistics_MultipleNumbers_ReturnsAverageOfNumbers(double input1, double input2, double input3)
        {
            // Arrange
            InMemoryBook book = new InMemoryBook("0");

            // Act
            book.AddGrade(input1, input2, input3);
            var result = book.GetStatistics();

            // Assert
            Assert.Equal(2, result.Average, 2);
        }
예제 #29
0
        public void CorrectValueAdded()
        {
            //Given
            var book = new InMemoryBook("Value Book");

            book.AddGrade(99.1);
            book.AddGrade(56.2);
            //When
            var result = book.GetStatistics();

            //Then
            Assert.Equal(99.1, result.High);
        }
예제 #30
0
        public void BookAddedGrade()
        {
            // arrange
            var book = new InMemoryBook("");


            // act section
            book.AddGrade(85);
            var stats = book.GetStatistics();

            // assert
            Assert.Equal('B', stats.Letter);
        }