Guest User

Untitled

a guest
Dec 5th, 2019
151
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using NUnit.Framework;
  2.  
  3. namespace Tests
  4. {
  5.     using CarManager; // <- comment this for judge
  6.     using System;
  7.  
  8.     public class CarTests
  9.     {
  10.         [SetUp]
  11.         public void Setup()
  12.         {
  13.         }
  14.  
  15.         [Test]
  16.         public void Constructor_InitCorrectly()
  17.         {
  18.             string make = "VW";
  19.             string model = "Golf";
  20.             double fuelConsumption = 2;
  21.             double fuelCap = 100;
  22.  
  23.             Car car = new Car(make, model, fuelConsumption, fuelCap);
  24.  
  25.             Assert.AreEqual(make, car.Make);
  26.             Assert.AreEqual(model, car.Model);
  27.             Assert.AreEqual(fuelConsumption, car.FuelConsumption);
  28.             Assert.AreEqual(fuelCap, car.FuelCapacity);
  29.         }
  30.  
  31.         // no need for these tests:
  32.         /*
  33.         [Test]
  34.         public void Model_ThrowArgumentException_NameIsNull()
  35.         {
  36.             // throw new ArgumentException("Make cannot be null or empty!");
  37.  
  38.             string make = "VW";
  39.             string model = null;
  40.             double fuelConsumption = 2;
  41.             double fuelCap = 100;
  42.  
  43.  
  44.             Assert.Throws<ArgumentException>( () => new Car(make, model, fuelConsumption, fuelCap));
  45.         }
  46.  
  47.         [Test]
  48.         public void Make_ThrowArgumentException_NameIsNull()
  49.         {
  50.             // throw new ArgumentException("Make cannot be null or empty!");
  51.  
  52.             string make = null;
  53.             string model = "Golf";
  54.             double fuelConsumption = 2;
  55.             double fuelCap = 100;
  56.  
  57.  
  58.             Assert.Throws<ArgumentException>(()
  59.                 => new Car(make, model, fuelConsumption, fuelCap));
  60.         }
  61.  
  62.         [Test]
  63.         public void FuelConsumption_ArgumentException_Negative()
  64.         {
  65.             string make = "VW";
  66.             string model = "Golf";
  67.             double fuelConsumption = -1;
  68.             double fuelCap = 100;
  69.  
  70.             Assert.Throws<ArgumentException>(()
  71.                 => new Car(make, model, fuelConsumption, fuelCap));
  72.         }
  73.  
  74.         [Test]
  75.         public void FuelConsumption_ArgumentException_Zero()
  76.         {
  77.             string make = "VW";
  78.             string model = "Golf";
  79.             double fuelConsumption = 0;
  80.             double fuelCap = 100;
  81.  
  82.             Assert.Throws<ArgumentException>(()
  83.                 => new Car(make, model, fuelConsumption, fuelCap));
  84.         }
  85.  
  86.         [Test]
  87.         public void FuelCap_ArgumentException_Zero()
  88.         {
  89.             string make = "VW";
  90.             string model = "Golf";
  91.             double fuelConsumption = 5;
  92.             double fuelCap = 0;
  93.  
  94.             Assert.Throws<ArgumentException>(()
  95.                 => new Car(make, model, fuelConsumption, fuelCap));
  96.         }
  97.  
  98.         [Test]
  99.         public void FuelCap_ArgumentException_Negative()
  100.         {
  101.             string make = "VW";
  102.             string model = "Golf";
  103.             double fuelConsumption = 2;
  104.             double fuelCap = -100;
  105.  
  106.             Assert.Throws<ArgumentException>(()
  107.                 => new Car(make, model, fuelConsumption, fuelCap));
  108.         }
  109.         */
  110.  
  111.         [Test]
  112.         [TestCase(null, "asd", 2, 5)]
  113.         [TestCase("asd", null, 5, 2)]
  114.         [TestCase("asd", "dsa", 0, 10)]
  115.         [TestCase("asd", "dsa", -1, 10)]
  116.         [TestCase("asd", "dsa", 10, 0)]
  117.         [TestCase("asd", "dsa", 10, -1)]
  118.         public void AllProperties_ThrowArgumentException_WhenInvalid
  119.             (string make, string model, double fuelCon, double fuelCap)
  120.         {
  121.             Assert.Throws<ArgumentException>(()
  122.                 => new Car(make, model, fuelCon, fuelCap));
  123.         }
  124.  
  125.         [Test]
  126.         public void RefuelNormally()
  127.         {
  128.             string make = "VW";
  129.             string model = "Golf";
  130.             double fuelConsumption = 2;
  131.             double fuelCap = 100;
  132.  
  133.             Car car = new Car(make, model, fuelConsumption, fuelCap);
  134.             car.Refuel(10);
  135.             double expectedFuelAmount = 10;
  136.             double actualFuelAmount = car.FuelAmount;
  137.  
  138.             Assert.AreEqual(expectedFuelAmount, actualFuelAmount);
  139.         }
  140.  
  141.         [Test]
  142.         public void RefuelCapsCorrectly()
  143.         {
  144.             string make = "VW";
  145.             string model = "Golf";
  146.             double fuelConsumption = 2;
  147.             double fuelCap = 100;
  148.  
  149.             Car car = new Car(make, model, fuelConsumption, fuelCap);
  150.             double tryToFuelAmount = 1000;
  151.             car.Refuel(tryToFuelAmount);
  152.  
  153.             double expectedFuelAmount = fuelCap;
  154.             double actualFuelAmount = car.FuelAmount;
  155.  
  156.             Assert.AreEqual(expectedFuelAmount, actualFuelAmount);
  157.         }
  158.  
  159.         [Test]
  160.         [TestCase(0)]
  161.         [TestCase(-10)]
  162.         public void Refuel_ArgumentException_Negative(double inputAmount)
  163.         {
  164.             string make = "VW";
  165.             string model = "Golf";
  166.             double fuelConsumption = 2;
  167.             double fuelCap = 100;
  168.             Car car = new Car(make, model, fuelConsumption, fuelCap);
  169.  
  170.             Assert.Throws<ArgumentException>(
  171.                 () => car.Refuel(inputAmount));
  172.         }
  173.  
  174.         [Test]
  175.         public void DriveNormally()
  176.         {
  177.             string make = "VW";
  178.             string model = "Golf";
  179.             double fuelConsumption = 2;
  180.             double fuelCap = 100;
  181.             Car car = new Car(make, model, fuelConsumption, fuelCap);
  182.  
  183.             car.Refuel(20);
  184.             car.Drive(20);
  185.  
  186.             double expectedFuelAmount = 19.6;
  187.             double actualFuelAmount = car.FuelAmount;
  188.  
  189.             Assert.AreEqual(expectedFuelAmount, actualFuelAmount);
  190.         }
  191.  
  192.         [Test]
  193.         [TestCase(1, 100)]
  194.         [TestCase(1, 51)]
  195.         [TestCase(9, 500)]
  196.         [TestCase(8, 444)]
  197.         [TestCase(10, 501)]
  198.         [TestCase(11, 666)]
  199.         public void Drive_ThrowInvalidOperationException_NotEnoughFuel
  200.             (double refuelAmount, double driveDistance)
  201.         {
  202.             string make = "VW";
  203.             string model = "Golf";
  204.             double fuelConsumption = 2;
  205.             double fuelCap = 100;
  206.             Car car = new Car(make, model, fuelConsumption, fuelCap);
  207.  
  208.             car.Refuel(refuelAmount);
  209.  
  210.             Assert.Throws<InvalidOperationException>(
  211.                 () => car.Drive(driveDistance));
  212.         }
  213.     }
  214. }
RAW Paste Data