Giter VIP home page Giter VIP logo

palindromes-csharp's Introduction

These setup instructions follow Week 1, Test-Driven Development with C# from Epicodus's C# and .Net curriculum

Setting up project from scratch

MSTest Configuration and Setup

After running dotnet restore and generating obj directories. In root directory: touch .gitignore and add to file */obj/

MSTest Writing and Running Tests

After setup, navigate to TDDcsharp.Tests and run dotnet test Tests will pass, even without testing code, because it didn't receive any compiler errors.

add */bin/ to .gitignore. Generated after running dotnet test

Our First Tests with MSTest

Following "Red, Green, Refactor" Workflow, test for isCar was added in this order:

  1. Identify the simplest possible behavior the program must exhibit"
my notes: "If string equals "car" return boolean true"
  1. Write a coded test

ModelTests/CarDealership.cs Note: Typo from previous commit. Change "public class CarDealership" to "public class CarDealershipTest

    [TestClass]
    public class CarDealershipTests
    {
        [TestMethod]
        public void isCar_StringEqualCar_True()
        {
            CarDealership testCarDealership = new CarDealership();
            Assert.AreEqual(true, testCarDealership.isCar("car"));
        }
    }

TDDcsharp/Models/CarDealership.cs (Nothing has changed. No code added yet)

    public class CarDealership
    {
        public bool isCar(string car)
        {
            return false;
        }
    }
  1. Confirm Test Fails

Navigate to TDDcsharp.Tests and run dotnet test test should fail - this is a good fail - Expected:. Actual: a compiler error is not a fail.

  1. Implement the behavior with the least amount of code possible

TDDcsharp/Models/CarDealership.cs

    public class CarDealership
    {
        public bool isCar(string car)
        {
            return car == "car";
        }
    }
  1. Confirm the test passes

Navigate to TDDchsarp.Tests and run dotnet test

  1. Confirm previous tests still pass N/A no previous tests at the moment so moving on.

  2. Check for refactoring Looks as DRY as it can be at the moment. Moving on.

  3. Repeat There is probably more that we could use to define a car. Such as, "4 wheels", "steering wheel", "brakes"

  4. Identify the simplest possible behavior the program must exhibit"

my notes: 
"If string equals "car" return boolean true"
"Other things makeup a car. If strings equals any of "car", "4 wheels", "steering wheel", "brakes" return boolean true
  1. Write a coded test

ModelTests/CarDealership.cs

    [TestClass]
    public class CarDealershipTests
    {
        [TestMethod]
        public void isCar_StringEqualCar_True()
        {
            CarDealership testCarDealership = new CarDealership();
            Assert.AreEqual(true, testCarDealership.isCar("car"));
        }

        [TestMethod]
        public void isCar_StringNotEqualCarThings_False()
        {
            CarDealership testCarDealership = new CarDealership();
            Assert.AreEqual(false, testCarDealership.isCar("horse"));
        }
    }
  1. Confirm test fails yes it does "car does not equal "horse"

  2. Implement the behavior with the least amount of code possible

    public class CarDealership
    {
        public bool isCar(string car)
        {
            string[] whatIsCarArray = {"car", "4 wheels", "brakes", "steering wheel"};
            
            foreach (string carThing in whatIsCarArray)
            {
                if(car == carThing)
                {
                    return true;
                }
            }
            return false;
        }
    }
  1. Confirm the test passes

Navigate to TDDchsarp.Tests and run dotnet test

  1. Confirm previous tests still pass isCar_StringEqualCar_True() changed name to isChar_StringEqualCarThing_True() test too with other things that should be true like "4 wheels" run test again confirm passes

  2. Check for refactoring Looks Dry but perhaps a way to loop over the first test so I don't have to add each thing at a time to test or repeat myself with lots of tests. Will leave as is for now since the array of things that define a car is fixed and confident if one string works then the rest will work

  3. Repeat What else can go in my car dealership?

palindromes-csharp's People

Contributors

saoud avatar

Watchers

 avatar James Cloos avatar

Forkers

shanole

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.