van Heemstra Systems.GitHub.io

van Heemstra Systems - Github io

View on GitHub

Step 3 - Coding: calculator

Following Test-Driven Development (TDD) principles, we'll now code the software for the calculator software system.

For the purpose of demonstration, we use different programming languages to achieve the same goal.

Step 3.1 - Coding in C#: calculator

GitHub

As we created a repository called 'calculator' at the start of our use case, we will now create a branch for our code in C#, as follows.

cd calculator
git branch csharp

Next, change our current branch to the 'csharp' branch.

git checkout csharp

From here on we will add and edit code for c# in this csharp branch, in a newly created directory called csharp.

mkdir csharp
cd csharp

After adding a project of type Class Library called 'Calculator' in Visual Studio, rename the autogenerated Class1.cs to Calculator.cs.

namespace Calculator
{
    public class Calculator
    {
        public string Message(string message)
        {
            return message;
        }
    }
}

Calculator.cs

Add the new directory to git:

git add Calculator/*

After adding a project of type Unit Test Project called 'Calculator.Tests' in Visual Studio, rename the autogenerated Class1.cs to CalculatorTests.cs.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Calculator;

namespace Calculator.Tests
{
    [TestClass]
    public class CalculatorTests
    {
        [TestMethod]
        [TestCategory("Message")]
        public void Message()
        {
            //Arrange
            var calculator = new Calculator();
            //Act
            string message = calculator.Message("Hello World!");
            //Assert
            Assert.AreEqual("Hello World!", message);
        }
    }
}

CalculatorTests.cs

Add a Reference to the 'Calculator' project in Calculator.Tests

Add the new directory to git:

git add CalculatorTests/*

more to follow...

Step 3.2 - Coding in Java: calculator

Link

Step 3.3 - Coding in JavaScript: calculator

Link

Step 3.4 - Coding in Python: calculator

Link