コード例 #1
0
        public void Test1()
        {
            UndergroundSystem undergroundSystem = new UndergroundSystem();

            undergroundSystem.CheckIn(45, "Leyton", 3);
            undergroundSystem.CheckIn(32, "Paradise", 8);
            undergroundSystem.CheckIn(27, "Leyton", 10);
            undergroundSystem.CheckOut(45, "Waterloo", 15);
            undergroundSystem.CheckOut(27, "Waterloo", 20);
            undergroundSystem.CheckOut(32, "Cambridge", 22);

            double average1 = undergroundSystem.GetAverageTime("Paradise", "Cambridge");

            average1.Should().Be(14.0);

            double average2 = undergroundSystem.GetAverageTime("Leyton", "Waterloo");

            average2.Should().Be(11.0);

            undergroundSystem.CheckIn(10, "Leyton", 24);
            double average3 = undergroundSystem.GetAverageTime("Leyton", "Waterloo");

            average3.Should().Be(11.0);

            undergroundSystem.CheckOut(10, "Waterloo", 38);
            double average4 = undergroundSystem.GetAverageTime("Leyton", "Waterloo");

            average4.Should().Be(12.0);
        }
コード例 #2
0
        public void GetAverageTime1()
        {
            var sut = new UndergroundSystem();

            sut.CheckIn(45, "Leyton", 3);
            sut.CheckIn(32, "Paradise", 8);
            sut.CheckIn(27, "Leyton", 10);
            sut.CheckOut(45, "Waterloo", 15);
            sut.CheckOut(27, "Waterloo", 20);
            sut.CheckOut(32, "Cambridge", 22);

            var actual = sut.GetAverageTime("Paradise", "Cambridge");

            Assert.AreEqual(14d, actual);

            actual = sut.GetAverageTime("Leyton", "Waterloo");
            Assert.AreEqual(11d, actual);

            sut.CheckIn(10, "Leyton", 24);
            actual = sut.GetAverageTime("Leyton", "Waterloo");
            Assert.AreEqual(11d, actual);

            sut.CheckOut(10, "Waterloo", 38);
            actual = sut.GetAverageTime("Leyton", "Waterloo");
            Assert.AreEqual(12d, actual);
        }
コード例 #3
0
        public void GivenUnderGroundSystem_GetAverage_ShouldReturnAverage()
        {
            var undergroundSystem = new UndergroundSystem();

            undergroundSystem.CheckIn(45, "Leyton", 3);
            undergroundSystem.CheckIn(32, "Paradise", 8);
            undergroundSystem.CheckIn(27, "Leyton", 10);
            undergroundSystem.CheckOut(45, "Waterloo", 15);
            undergroundSystem.CheckOut(27, "Waterloo", 20);
            undergroundSystem.CheckOut(32, "Cambridge", 22);

            var result = undergroundSystem.GetAverageTime("Paradise", "Cambridge");

            Assert.IsTrue(result == 14.0d);
        }
コード例 #4
0
    public static void Main(string[] args)
    {
        UndergroundSystem undergroundSystem = new UndergroundSystem();

        undergroundSystem.CheckIn(45, "Leyton", 3);
        undergroundSystem.CheckIn(32, "Paradise", 8);
        undergroundSystem.CheckIn(27, "Leyton", 10);
        undergroundSystem.CheckOut(45, "Waterloo", 15);
        undergroundSystem.CheckOut(27, "Waterloo", 20);
        undergroundSystem.CheckOut(32, "Cambridge", 22);
        Console.WriteLine(undergroundSystem.GetAverageTime("Paradise", "Cambridge"));   // return 14.0. There was only one travel from "Paradise" (at time 8) to "Cambridge" (at time 22)
        Console.WriteLine(undergroundSystem.GetAverageTime("Leyton", "Waterloo"));      // return 11.0. There were two travels from "Leyton" to "Waterloo", a customer with id=45 from time=3 to time=15 and a customer with id=27 from time=10 to time=20. So the average time is ( (15-3) + (20-10) ) / 2 = 11.0
        undergroundSystem.CheckIn(10, "Leyton", 24);
        Console.WriteLine(undergroundSystem.GetAverageTime("Leyton", "Waterloo"));      // return 11.0
        undergroundSystem.CheckOut(10, "Waterloo", 38);
        Console.WriteLine(undergroundSystem.GetAverageTime("Leyton", "Waterloo"));      // return 12.0
    }
コード例 #5
0
        public void GetAverageTime2()
        {
            var sut = new UndergroundSystem();

            sut.CheckIn(10, "Leyton", 3);
            sut.CheckOut(10, "Paradise", 8);

            var actual = sut.GetAverageTime("Leyton", "Paradise");

            Assert.AreEqual(5d, actual);

            sut.CheckIn(5, "Leyton", 10);
            sut.CheckOut(5, "Paradise", 16);
            actual = sut.GetAverageTime("Leyton", "Paradise");
            Assert.AreEqual(5.5d, actual);

            sut.CheckIn(2, "Leyton", 21);
            sut.CheckOut(2, "Paradise", 30);
            actual = sut.GetAverageTime("Leyton", "Paradise");
            Assert.AreEqual(6.666666666666667d, actual);
        }
コード例 #6
0
        public void Test2()
        {
            UndergroundSystem undergroundSystem = new UndergroundSystem();

            undergroundSystem.CheckIn(10, "Leyton", 3);
            undergroundSystem.CheckOut(10, "Paradise", 8);
            double average1 = undergroundSystem.GetAverageTime("Leyton", "Paradise");

            average1.Should().Be(5.0);

            undergroundSystem.CheckIn(5, "Leyton", 10);
            undergroundSystem.CheckOut(5, "Paradise", 16);
            double average2 = undergroundSystem.GetAverageTime("Leyton", "Paradise");

            average2.Should().Be(5.5);

            undergroundSystem.CheckIn(2, "Leyton", 21);
            undergroundSystem.CheckOut(2, "Paradise", 30);
            double average3 = undergroundSystem.GetAverageTime("Leyton", "Paradise");

            average3.Should().BeApproximately(6.66667, 0.001);
        }
コード例 #7
0
        /*
         * ["UndergroundSystem","checkIn","checkIn","checkIn","checkOut","checkOut","checkOut","getAverageTime","getAverageTime","checkIn","getAverageTime","checkOut","getAverageTime"]
         * [[],[45,"Leyton",3],[32,"Paradise",8],[27,"Leyton",10],[45,"Waterloo",15],[27,"Waterloo",20],[32,"Cambridge",22],["Paradise","Cambridge"],["Leyton","Waterloo"],[10,"Leyton",24],["Leyton","Waterloo"],[10,"Waterloo",38],["Leyton","Waterloo"]]
         * [null,null,null,null,null,null,null,14.00000,11.00000,null,11.00000,null,12.00000]
         *
         */
        public void Case0()
        {
            var subway = new UndergroundSystem();

            subway.CheckIn(45, "Leyton", 3);
            subway.CheckIn(32, "Paradise", 8);
            subway.CheckIn(27, "Leyton", 10);

            subway.CheckOut(45, "Waterloo", 15);
            subway.CheckOut(27, "Waterloo", 20);
            subway.CheckOut(32, "Cambridge", 22);

            Assert.Equal(14, subway.GetAverageTime("Paradise", "Cambridge"));
            Assert.Equal(11, subway.GetAverageTime("Leyton", "Waterloo"));

            subway.CheckIn(10, "Leyton", 24);

            Assert.Equal(11, subway.GetAverageTime("Leyton", "Waterloo"));
            subway.CheckOut(10, "Waterloo", 38);

            Assert.Equal(12, subway.GetAverageTime("Leyton", "Waterloo"));
        }