示例#1
0
    public static List <ProductionRemoteControlCar> GetRankedCars(ProductionRemoteControlCar prc1, ProductionRemoteControlCar prc2)
    {
        var productionRemoteControlCars = new List <ProductionRemoteControlCar> {
            prc1, prc2
        };

        productionRemoteControlCars.Sort();

        return(productionRemoteControlCars);
    }
    public void Race()
    {
        var productionCar   = new ProductionRemoteControlCar();
        var experimentalCar = new ExperimentalRemoteControlCar();

        TestTrack.Race((IRemoteControlCar)productionCar);
        TestTrack.Race((IRemoteControlCar)productionCar);
        TestTrack.Race((IRemoteControlCar)experimentalCar);
        TestTrack.Race((IRemoteControlCar)experimentalCar);
        Assert.Equal(20, experimentalCar.DistanceTravelled - productionCar.DistanceTravelled);
    }
    public void ComparisonIsNullSafe()
    {
        ProductionRemoteControlCar nullCar   = null;
        ProductionRemoteControlCar normalCar = new();
        var cars = new List <ProductionRemoteControlCar> {
            normalCar, nullCar
        };

        cars.Sort();
        Assert.Equal(new ProductionRemoteControlCar[] { nullCar, normalCar }, cars);
    }
    public void RankCars()
    {
        var prc1 = new ProductionRemoteControlCar();
        var prc2 = new ProductionRemoteControlCar();

        prc1.NumberOfVictories = 3;
        prc2.NumberOfVictories = 2;
        var rankings = TestTrack.GetRankedCars(prc1, prc2);

        Assert.Same(prc1, rankings[1]);
    }
    public static List <ProductionRemoteControlCar> GetRankedCars(
        ProductionRemoteControlCar prc1,
        ProductionRemoteControlCar prc2)
    {
        var rankingList = new List <ProductionRemoteControlCar>()
        {
            prc1, prc2
        };

        rankingList.Sort();

        return(rankingList);
    }
    public void EnsureCarsAreComparable()
    {
        var fast   = new ProductionRemoteControlCar();
        var medium = new ProductionRemoteControlCar();
        var slow   = new ProductionRemoteControlCar();

        fast.NumberOfVictories   = 3;
        medium.NumberOfVictories = 2;
        slow.NumberOfVictories   = 1;
        var cars = new List <ProductionRemoteControlCar> {
            fast, slow, medium
        };

        cars.Sort();
        Assert.Equal(new ProductionRemoteControlCar[] { slow, medium, fast }, cars);
    }
 public static List <ProductionRemoteControlCar> GetRankedCars(ProductionRemoteControlCar prc1,
                                                               ProductionRemoteControlCar prc2)
 {
     throw new NotImplementedException($"Please implement the (static) TestTrack.GetRankedCars() method");
 }