Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,194,687 members, 7,955,578 topics. Date: Sunday, 22 September 2024 at 09:35 AM

Jacob05's Posts

Nairaland Forum / Jacob05's Profile / Jacob05's Posts

(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) (11) (12) (of 37 pages)

Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 3:28pm On Aug 10, 2015
We'd Implement Mixed Fraction Later...

Your thoughts ?
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 3:23pm On Aug 10, 2015
Implementing the Console App for Our Ordinary Fraction Operations
Before we can make use of our Fraction Class in the Console App project we need to add a reference to the FractionLibrary project.
1) Right Click On References under FractionConsoleApp project in the Solution Explorer -> Click Add Reference

[img]http:///a/img538/9408/1jN64u.jpg[/img]

2) Check FractionLibrary in the list. Click Ok

[img]http:///a/img912/7441/hNFdXu.jpg[/img]

3) Update Program.cs in FractionConsoleApp[/b]project, adding [b] using FractionLibrary;
Our Program.cs Class now

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FractionLibrary;

namespace FractionConsoleApp
{
class Program
{
static void Main(string[] args)
{

}
}
}

How do we go about implementing the operations……
Lets first write a simple algorithm …
1) Display Welcome Message
2) Display Available Operations
3) Accept Type of Operation to be performed
4) If Operation to be performed is a binary Operation
a. Accept FirstFraction
1) If accepted value is not valid, request for another until correct value inputted
b. Accept SecondFraction
1) If accepted value is not valid, request for another until correct value inputted
c. Perform Selected Operation on two fractions
5) If Operation to be performed is a Unary Operation
a. Accept SingleFraction
1) If accepted value is not valid, request for another until correct value inputted
b. Perform Selected Operation on fraction
6) Output result

1. Display Welcome Message: Let’s create a method named displayWelcomeMessage to display necessary welcome message

public static void displayWelcomeMessage()
{
Console.Write("Welcome to the Most Powerful "wink;
Console.WriteLine("Fractions Calculator in World!!!\n"wink;
}


2. Display Available Operations: We can write a method named displayAvailableOperations to display the Operations

Console.WriteLine(" Available Operations"wink;
Console.WriteLine("======================"wink;
Console.WriteLine("(1). Addition"wink;
Console.WriteLine("(2). Subtraction"wink;
Console.WriteLine("(3). Division"wink;
Console.WriteLine("(4). Multiplication"wink;
Console.WriteLine("(5). Decrement"wink;
Console.WriteLine("(6). Increment"wink;

3. Accept Type of Operation to be performed: We’d write a method named getTypeOfOperationToPerform to accept and return an integer value representing the type of operation the user wants to perform
 
public static int getTypeOfOperationToPerform()
{
int operation = 0;
while (operation == 0)
{
Console.Write("Please, Enter Operation to perform [1-6]: "wink;
String op = Console.ReadLine();
int.TryParse(op, out operation);
if (operation == 0 || operation >= 7)
{
Console.WriteLine("Invalid Input Value"wink;
operation = 0; //Reset
}
}
return operation;

}

4. If Operation to be is a binary Operation: Operations 1 to 4 requires two fractions, we need a condition to check this. So that we can accept two fractions.

if (operation <= 4)
{

}


5. Accept FirstFraction and Accept SecondFraction: Since these two steps are doing the same thing but with a different prompt. we can write a method named getSingleFractionFromUser to accept a fraction from the user which the two methods , getFirstFraction and getSecondFraction, we’re going to create, would call.


private static Fraction getSingleFractionFromUser(){
Fraction result = new Fraction();
bool correctValueAccepted = false;
while (!correctValueAccepted)
{
String acceptedFraction = Console.ReadLine();
try{
result = acceptedFraction;
correctValueAccepted = true;
}catch(Exception e){
Console.WriteLine("Invalid/Unable to Parse Input Fraction"wink;
Console.Write("Please, Enter a Fraction [e.g. 1/2]: "wink;
}
}
return result;
}

private static Fraction getFirstFraction(){
Console.Write("Please, Enter a First Fraction [e.g. 1/2]: "wink;
Fraction FirstFraction = getSingleFractionFromUser();
return FirstFraction;
}
private static Fraction getSecondFraction(){
Console.Write("Please, Enter a Second Fraction [e.g. 1/2]: "wink;
Fraction SecondFraction = getSingleFractionFromUser();
return SecondFraction;
}


6. Perform Selected Operation on two fractions : To Implement this, we would need a condition to Determine which of the 4 binary operations is chosen. So that the need operation is performed. We’d create a method named performBinaryOperation that accepts, as arguments, the operation to be performed and the first and second Fraction. The method then returns the result.

private static Fraction performBinaryOperation(int operation,Fraction firstFraction, Fraction secondFraction)
{
Fraction result;
switch (operation)
{
case 1:
result = firstFraction + secondFraction;
break;
case 2:
result = firstFraction - secondFraction;
break;
case 3:
result = firstFraction / secondFraction;
break;
default: //Case 4
result = firstFraction * secondFraction;
break;
}
return result;
}

7. If Operation to be performed is a Unary Operation: Operations 5 and 6 requires One fraction, we need a condition to check this. So that we can accept One fraction.

if (operation > 4 && operation <= 6)
{

}


8. Accept SingleFraction: Let’s Create a method named getSingleFraction

private static Fraction getSingleFraction()
{
Console.Write("Please, Enter a Fraction [e.g. 1/2]: "wink;
Fraction fraction = getSingleFractionFromUser();
return fraction;
}

9. Perform Selected Operation on fraction: To Implement this, we would need a condition to Determine which of the 2 Unary operations is chosen. So that the need operation is performed. We’d create a method named performUnaryOperation that accepts, as arguments, the operation to be performed and Fraction. The method then returns the result.

private static Fraction performUnaryOperation(int operation, Fraction fraction)
{
Fraction result = new Fraction();
if (operation == 5) result = --fraction;
if (operation == 6) result = ++fraction;
return result;
}

10. Output result: Let’s make this simple

Console.WriteLine("The result is: {0}", result);

PUTTING IT ALL TOGETHER
Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FractionLibrary;

namespace FractionConsoleApp
{
class Program
{
static void Main(string[] args)
{
Fraction firstFraction = new Fraction();
Fraction secondFraction = new Fraction();
Fraction result = new Fraction();

displayWelcomeMessage();
displayAvailableOperations();
int operation = getTypeOfOperationToPerform();
if (operation <= 4)
{
firstFraction = getFirstFraction();
secondFraction = getSecondFraction();
result = performBinaryOperation(operation,firstFraction, secondFraction);
}
if (operation > 4 && operation <= 6)
{
firstFraction = getSingleFraction();
result = performUnaryOperation(operation,firstFraction);
}

Console.WriteLine("The result is: {0}", result);
Console.Read();
}

private static Fraction performUnaryOperation(int operation, Fraction fraction)
{
Fraction result = new Fraction();
if (operation == 5) result = --fraction;
if (operation == 6) result = ++fraction;
return result;
}

private static Fraction performBinaryOperation(int operation,Fraction firstFraction, Fraction secondFraction)
{
Fraction result;
switch (operation)
{
case 1:
result = firstFraction + secondFraction;
break;
case 2:
result = firstFraction - secondFraction;
break;
case 3:
result = firstFraction / secondFraction;
break;
default: //Case 4
result = firstFraction * secondFraction;
break;
}
return result;
}

public static void displayWelcomeMessage()
{
Console.Write("Welcome to the Most Powerful "wink;
Console.WriteLine("Fractions Calculator in World !!!\n"wink;
}
public static void displayAvailableOperations()
{
Console.WriteLine(" Available Operations"wink;
Console.WriteLine("======================"wink;
Console.WriteLine("(1). Addition"wink;
Console.WriteLine("(2). Subtraction"wink;
Console.WriteLine("(3). Division"wink;
Console.WriteLine("(4). Multiplication"wink;
Console.WriteLine("(5). Decrement"wink;
Console.WriteLine("(6). Increment"wink;
}

public static int getTypeOfOperationToPerform()
{
int operation = 0;
while (operation == 0)
{
Console.Write("Please, Enter Operation to perform [1-6]: "wink;
String op = Console.ReadLine();
int.TryParse(op, out operation);
if (operation == 0 || operation >= 7)
{
Console.WriteLine("Invalid Input Value"wink;
operation = 0; //Reset
}
}
return operation;

}

private static Fraction getSingleFractionFromUser(){
Fraction result = new Fraction();
bool correctValueAccepted = false;
while (!correctValueAccepted)
{
String acceptedFraction = Console.ReadLine();
try{
result = acceptedFraction;
correctValueAccepted = true;
}catch(Exception e){
Console.WriteLine("Invalid/Unable to Parse Input Fraction"wink;
Console.Write("Please, Enter a Fraction [e.g. 1/2]: "wink;
}
}
return result;
}

private static Fraction getFirstFraction(){
Console.Write("Please, Enter a First Fraction [e.g. 1/2]: "wink;
Fraction FirstFraction = getSingleFractionFromUser();
return FirstFraction;
}
private static Fraction getSecondFraction(){
Console.Write("Please, Enter a Second Fraction [e.g. 1/2]: "wink;
Fraction SecondFraction = getSingleFractionFromUser();
return SecondFraction;
}

private static Fraction getSingleFraction()
{
Console.Write("Please, Enter a Fraction [e.g. 1/2]: "wink;
Fraction fraction = getSingleFractionFromUser();
return fraction;
}

}
}

Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 3:18pm On Aug 10, 2015
IMPLEMENTING THE TOSTRING METHOD

Overriding C#’s ToString method would enable us to define how we want our Fraction class to be displayed as a String.
So that we can achieve the below

[img]http:///a/img661/8026/uxIU5a.jpg[/img]

Let’s Write the Tests in the tests class.

[TestMethod]
public void testOrdinaryFractionsToString()
{

Fraction result = new Fraction(1,2);

Assert.AreEqual("1/2", result.ToString());

result = "5/10";

Assert.AreEqual("5/10", result.ToString());

}


[img]http:///a/img540/6037/oTKPlN.jpg[/img]

Let’s implement the method in the Fraction Class (NOTE: FOLLOW THE PASS -> FAIL -> PASS METHOD)

public override string ToString()
{
return string.Format("{0}/{1}", this.Numerator,
this.Denominator);
}


[img]http:///a/img540/2245/s3UnY6.jpg[/img]

Run the tests !!! …. They should all pass ..

[img]http:///a/img911/2290/hL7efq.jpg[/img]


Now Let’s implement the Console App for Our Ordinary Fraction Operations.
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 3:13pm On Aug 10, 2015
IMPLEMENTING SYNTACTIC SUGARS

What if we want to achieve something like this

[img]http:///a/img661/5507/sHpT7q.jpg[/img]

We can implement this by implementing a static implicit cast method on Strings;
To best illustrate this syntactic sugar, let’s first write the test in the tests Class.

[TestMethod]
public void testOrdinaryFractionsStringToOrdinaryFraction()
{

Fraction result = "1/2";

Assert.AreEqual(1, result.Numerator);
Assert.AreEqual(2, result.Denominator);

result = "5/10";

Assert.AreEqual(5, result.Numerator);
Assert.AreEqual(10, result.Denominator);

try
{
result = "1g/2f";
Assert.Fail("Shouldn't be able to Create a Fraction with invalid Values"wink;
}
catch (Exception ex) { }

}


[img]http:///a/img905/4747/BxXj0j.jpg[/img]

Let’s implement the method in the Fraction Class (NOTE: FOLLOW THE PASS -> FAIL -> PASS METHOD)

public static implicit operator Fraction(String value)
{
string[] v = value.Split('/');
int newNumerator = int.Parse(v[0]);
int newDenominator = int.Parse(v[1]);
return new Fraction(newNumerator, newDenominator);

}


[img]http:///a/img912/3999/0Njo8J.jpg[/img]

NOTE: the int.Parse method throws an Exception if the input String is not valid.
Run the tests !!!..
They should pass. (NOTE: FOLLOW THE PASS -> FAIL -> PASS METHOD)

[img]http:///a/img911/4578/ATzbPD.jpg[/img]

Now Let’s implement the ToString method.
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 3:06pm On Aug 10, 2015
IMPLEMETING INCREMENT, DECREMENT, AND SYNATACTIC SUGARS

Incrementing a fraction involves adding One to the fraction. But it is not that straight forward. To add 1 to a fraction we create a fraction with the Numerator and Denominator set to 1 and then we Add the fraction to our fraction. The same goes for decrement but we’ll do subtraction

[img]http:///a/img901/9121/ngdmmi.jpg[/img]

Ok. Just like Addition, we can implement increment and decrement using method and operator overloading.
Let’s begin by writing our tests in the tests class

[TestMethod]
public void testOrdinaryFractionsIncrementUsingMethod()
{
Fraction firstFraction = new Fraction(1, 2);
Fraction result = firstFraction.Increment();

Assert.AreEqual(3, result.Numerator);
Assert.AreEqual(2, result.Denominator);
}
[TestMethod]
public void testOrdinaryFractionsIncrementUsingOpOverloading()
{

Fraction firstFraction = new Fraction(1, 2);

Fraction result = ++firstFraction;

Assert.AreEqual(3, result.Numerator);
Assert.AreEqual(2, result.Denominator);

}


[img]http:///a/img673/1175/6VTdCS.jpg[/img]

Our Code Won’t Compile because of the unimplemented method and operator. For the sake of brevity I would implement them directly not just implementing it just to make current test pass BUT you should follow the method I followed earlier by implementing a simple method that would make it pass then add another test that would fail the make it pass.
Let’s implement them in the Fraction class.

public Fraction Increment()
{
Fraction One = new Fraction(1,1);

return One + this;
}

public static Fraction operator ++(Fraction firstFraction)
{
Fraction One = new Fraction(1, 1);

return One + firstFraction;

}


[img]http:///a/img540/9593/OiYJOI.jpg[/img]

Run the Tests
Passed !!!

[img]http:///a/img901/5940/r6gSuJ.jpg[/img]

Let’s quickly implement Decrement in the tests class
Our Tests for Decrement

[TestMethod]
public void testOrdinaryFractionsDecrementUsingMethod()
{
Fraction firstFraction = new Fraction(3, 2);
Fraction result = firstFraction.Decrement();

Assert.AreEqual(1, result.Numerator);
Assert.AreEqual(2, result.Denominator);
}
[TestMethod]
public void testOrdinaryFractionsDecrementUsingOpOverloading()
{

Fraction firstFraction = new Fraction(3, 2);

Fraction result = --firstFraction;

Assert.AreEqual(1, result.Numerator);
Assert.AreEqual(2, result.Denominator);

}


[img]http:///a/img910/61/7bjY9t.jpg[/img]

Our Code Won’t Compile because of the unimplemented method and operator. For the sake of brevity I would implement them directly not just implementing it just to make current test pass.
Let’s implement them in the Fraction class.

public Fraction Decrement()
{
Fraction One = new Fraction(1, 1);

return this - One;
}

public static Fraction operator --(Fraction firstFraction)
{
Fraction One = new Fraction(1, 1);

return firstFraction - One;

}


[img]http:///a/img673/7899/w7vw7C.jpg[/img]
Run the Tests
Passed !!!

[img]http:///a/img661/1806/fbWSoV.jpg[/img]
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 1:59pm On Aug 10, 2015
IMPLEMENTING SUBTRACTION, MULTIPLICATION AND DIVISION
TESTS FOR SUBTRACTION

[TestMethod]
public void testOrdinaryFractionsSubstractionUsingMethod()
{
Fraction firstFraction = new Fraction(5, 10);
Fraction secondFraction = new Fraction(3, 9);
Fraction result = firstFraction.Substract(secondFraction);

Assert.AreEqual(15, result.Numerator);
Assert.AreEqual(90, result.Denominator);

firstFraction = new Fraction(6, 10);
secondFraction = new Fraction(7, 20);
result = firstFraction.Substract(secondFraction);

Assert.AreEqual(50, result.Numerator);
Assert.AreEqual(200, result.Denominator);


}

[TestMethod]
public void testOrdinaryFractionsSubstractionUsingOpOverloading()
{

Fraction firstFraction = new Fraction(5, 10);
Fraction secondFraction = new Fraction(3, 9);
Fraction result = firstFraction - secondFraction;

Assert.AreEqual(15, result.Numerator);
Assert.AreEqual(90, result.Denominator);

firstFraction = new Fraction(6, 10);
secondFraction = new Fraction(7, 20);
result = firstFraction - secondFraction;

Assert.AreEqual(50, result.Numerator);
Assert.AreEqual(200, result.Denominator);

}






METHODS FOR SUBSTRACTION

public Fraction Substract(Fraction secondFraction)
{
int newNumerator = (this.Numerator * secondFraction.Denominator) -
(secondFraction.Numerator * this.Denominator);
int newDenominator = this.Denominator * secondFraction.Denominator;
return new Fraction(newNumerator, newDenominator);

}

public static Fraction operator -(Fraction firstFraction, Fraction secondFraction)
{
int newNumerator = (firstFraction.Numerator * secondFraction.Denominator) -
(secondFraction.Numerator * firstFraction.Denominator);
int newDenominator = firstFraction.Denominator * secondFraction.Denominator;
return new Fraction(newNumerator, newDenominator);

}

TESTS FOR MULTIPLICATION

[TestMethod]
public void testOrdinaryFractionsMultiplicationUsingMethod()
{
Fraction firstFraction = new Fraction(5, 10);
Fraction secondFraction = new Fraction(3, 9);
Fraction result = firstFraction.Multiply(secondFraction);

Assert.AreEqual(15, result.Numerator);
Assert.AreEqual(90, result.Denominator);

firstFraction = new Fraction(6, 10);
secondFraction = new Fraction(7, 20);
result = firstFraction.Multiply(secondFraction);

Assert.AreEqual(42, result.Numerator);
Assert.AreEqual(200, result.Denominator);


}
[TestMethod]
public void testOrdinaryFractionsMultiplicationUsingOpOverloading()
{

Fraction firstFraction = new Fraction(5, 10);
Fraction secondFraction = new Fraction(3, 9);
Fraction result = firstFraction * secondFraction;

Assert.AreEqual(15, result.Numerator);
Assert.AreEqual(90, result.Denominator);

firstFraction = new Fraction(6, 10);
secondFraction = new Fraction(7, 20);
result = firstFraction * secondFraction;

Assert.AreEqual(42, result.Numerator);
Assert.AreEqual(200, result.Denominator);

}


METHODS FOR MULTIPLICATION

public Fraction Multiply(Fraction secondFraction)
{
int newNumerator = this.Numerator * secondFraction.Numerator;

int newDenominator = this.Denominator * secondFraction.Denominator;
return new Fraction(newNumerator, newDenominator);
}

public static Fraction operator *(Fraction firstFraction, Fraction secondFraction)
{
int newNumerator = firstFraction.Numerator * secondFraction.Numerator;

int newDenominator = firstFraction.Denominator * secondFraction.Denominator;
return new Fraction(newNumerator, newDenominator);

}

TESTS FOR DIVISION

[TestMethod]
public void testOrdinaryFractionsDivisionUsingMethod()
{
Fraction firstFraction = new Fraction(5, 10);
Fraction secondFraction = new Fraction(3, 9);
Fraction result = firstFraction.Divide(secondFraction);

Assert.AreEqual(45, result.Numerator);
Assert.AreEqual(30, result.Denominator);

firstFraction = new Fraction(6, 10);
secondFraction = new Fraction(7, 20);
result = firstFraction.Divide(secondFraction);

Assert.AreEqual(120, result.Numerator);
Assert.AreEqual(70, result.Denominator);


}
[TestMethod]
public void testOrdinaryFractionsDivisionUsingOpOverloading()
{

Fraction firstFraction = new Fraction(5, 10);
Fraction secondFraction = new Fraction(3, 9);
Fraction result = firstFraction / secondFraction;

Assert.AreEqual(45, result.Numerator);
Assert.AreEqual(30, result.Denominator);

firstFraction = new Fraction(6, 10);
secondFraction = new Fraction(7, 20);
result = firstFraction / secondFraction;

Assert.AreEqual(120, result.Numerator);
Assert.AreEqual(70, result.Denominator);

}



METHODS FOR DIVISION


public Fraction Divide(Fraction secondFraction)
{
int newNumerator = this.Numerator * secondFraction.Denominator ;

int newDenominator = this.Denominator * secondFraction.Numerator;
return new Fraction(newNumerator, newDenominator);
}

public static Fraction operator /(Fraction firstFraction, Fraction secondFraction)
{
int newNumerator = firstFraction.Numerator * secondFraction.Denominator;

int newDenominator = firstFraction.Denominator * secondFraction.Numerator;
return new Fraction(newNumerator, newDenominator);

}

Next, Run the tests.
Passed !!!
[img]http:///a/img909/4167/tA3B8s.png[/img]
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 1:43pm On Aug 10, 2015
BEGINNING TESTS: TESTING ADDITION OF ORDINARY FRACTIONS 2
The next Test Would be straight forward.
We’d be leveraging on C#’s operator Overloading support to create a nice addition interface.
Let’s write the Test !!!.
Update the Test Method testOrdinaryFractionsAdditionsUsingOpOverloading to


[TestMethod]
public void testOrdinaryFractionsAdditionsUsingOpOverloading()
{

Fraction firstFraction = new Fraction(5, 10);
Fraction secondFraction = new Fraction(3, 9);
Fraction result = firstFraction + secondFraction;

Assert.AreEqual(75, result.Numerator);
Assert.AreEqual(90, result.Denominator);

}

Notice the Red wiggly under firstFraction + secondFraction and the message : Operator '+' cannot be applied to operands of type 'FractionLibrary.Fraction' and 'FractionLibrary.Fraction';

[img]http:///a/img540/2129/TKoSlp.png[/img]

C# allow us to overload the + operator when use it on our class. This is done by creating method named operator followed by the + sign.
Let’s Implement it to just [b] pass this test.
Add this method to [b] Fraction.cs
class

public static Fraction operator +(Fraction firstFraction, Fraction secondFraction)
{
return new Fraction(75, 90);
}

Weird Method Huh? You can Learn More about Operator Overloading via Google or Books.
Notice the Red wiggly line is gone.
Let’s Run the Test Again
Passed !!!
[img]http:///a/img538/4214/GuztLa.jpg[/img]

Now Let’s make how test fail so that we can compute the values.
Update the Test Method testOrdinaryFractionsAdditionsUsingOpOverloading

[TestMethod]
public void testOrdinaryFractionsAdditionsUsingOpOverloading()
{

Fraction firstFraction = new Fraction(5, 10);
Fraction secondFraction = new Fraction(3, 9);
Fraction result = firstFraction + secondFraction;

Assert.AreEqual(75, result.Numerator);
Assert.AreEqual(90, result.Denominator);

firstFraction = new Fraction(6, 10);
secondFraction = new Fraction(7, 20);
result = firstFraction + secondFraction;

Assert.AreEqual(190, result.Numerator);
Assert.AreEqual(200, result.Denominator);

}

Run the Tests..
It Should Fail, With the Message : Expected<190> .Actual<75>

Now Let’s Make it Pass By Updating the Overload Method to do actual Calculation.

public static Fraction operator +(Fraction firstFraction, Fraction secondFraction)
{
int newNumerator = (firstFraction.Numerator * secondFraction.Denominator) +
(secondFraction.Numerator * firstFraction.Denominator);
int newDenominator = firstFraction.Denominator * secondFraction.Denominator;
return new Fraction(newNumerator, newDenominator);
}


Save and Run the test File Again.
Tests should Pass


FractionArithmeticTests.cs

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

using FractionLibrary;

namespace FractionTest
{
[TestClass]
public class FractionArithmeticTests
{

[TestMethod]
public void testOrdinaryFractionCreation()
{
Fraction firstFraction = new Fraction();

Assert.AreEqual(0, firstFraction.Numerator);
Assert.AreEqual(0, firstFraction.Denominator);

firstFraction = new Fraction(5,10);
Assert.AreEqual(5, firstFraction.Numerator);
Assert.AreEqual(10, firstFraction.Denominator);

firstFraction = new Fraction(10, 5);
Assert.AreEqual(10, firstFraction.Numerator);
Assert.AreEqual(5, firstFraction.Denominator);

try{

firstFraction = new Fraction(0, 1);
Assert.Fail("Shouldn't be able to Create a Fraction with Zero Numerator"wink;
}
catch (ArgumentOutOfRangeException ex){}

try
{

firstFraction = new Fraction(1, 0);
Assert.Fail("Shouldn't be able to Create a Fraction with Zero Denominator"wink;
}
catch (ArgumentOutOfRangeException ex) { }


}

[TestMethod]
public void testOrdinaryFractionsAdditionsUsingMethod()
{
Fraction firstFraction = new Fraction(5,10);
Fraction secondFraction = new Fraction(3,9);
Fraction result = firstFraction.Add(secondFraction);

Assert.AreEqual(75, result.Numerator);
Assert.AreEqual(90, result.Denominator);

firstFraction = new Fraction(6, 10);
secondFraction = new Fraction(7, 20);
result = firstFraction.Add(secondFraction);

Assert.AreEqual(190, result.Numerator);
Assert.AreEqual(200, result.Denominator);


}

[TestMethod]
public void testOrdinaryFractionsAdditionsUsingOpOverloading()
{

Fraction firstFraction = new Fraction(5, 10);
Fraction secondFraction = new Fraction(3, 9);
Fraction result = firstFraction + secondFraction;

Assert.AreEqual(75, result.Numerator);
Assert.AreEqual(90, result.Denominator);



}

}
}


Fraction.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FractionLibrary
{
public class Fraction
{

public Fraction(int numerator, int denominator)
{
// TODO: Complete member initialization
if (numerator == 0) { throw new ArgumentOutOfRangeException("Numerator Can't be Zero"wink; }
if (denominator == 0) { throw new ArgumentOutOfRangeException("Denominator Can't be Zero"wink; }

this.Numerator = numerator;
this.Denominator = denominator;
}

public Fraction()
{
// TODO: Complete member initialization
}

public int Numerator
{
get;
set;
}

public int Denominator
{
get;
set;

}

public Fraction Add(Fraction secondFraction)
{
int newNumerator = (this.Numerator * secondFraction.Denominator) +
(secondFraction.Numerator * this.Denominator);
int newDenominator = this.Denominator * secondFraction.Denominator;
return new Fraction(newNumerator, newDenominator);

}

public static Fraction operator +(Fraction firstFraction, Fraction secondFraction)
{
int newNumerator = (firstFraction.Numerator * secondFraction.Denominator) +
(secondFraction.Numerator * firstFraction.Denominator);
int newDenominator = firstFraction.Denominator * secondFraction.Denominator;
return new Fraction(newNumerator, newDenominator);

}
}
}




FROM THE ABOVE, IMPLEMENTING SUBTRACTION, MULTIPLICATION AND DIVISION WOULD BE VERY EASY SO I WON’T DISCUSS MUCH ON IT BUT WOULD PASTE THE TESTS AND METHODS. I’D ADVISE YOU FOLLOW THE STEPS I FOLLOWED WHILE IMPLEMENTING THE ADDITION OPERATION. FIRST MAKE THE TEST COMPILE BY ADDING A RETURN VALUE THAT WOULD JUST MAKE IT PASS. THEN ADD ANOTHER TEST THAT WOULD MAKE IT FAIL THEN, FINALLY, FIX THE FUNCTION TO MAKE THE THIS PASS.
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 11:30am On Aug 10, 2015
Check My Posts Again...Updated the Posts
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 11:28am On Aug 10, 2015
I noted a Veeeeery BIG logical error in the Whole App.... I feel very ashamed wink... But why can't you guys point it out in the first Place...

Calculations for Addition and the rest are totally wrong !!!!....
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 11:25am On Aug 10, 2015
Finally.. Back online
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 1:43pm On Aug 07, 2015
i'm sorry i haven't updated and conclude this simple tut.

Lost my phone. (my hotspot lolz). I would torrent all the remain updates when i secure a good internet source.

thanks for your contributions and followership
Software/Programmer Market / Re: Create Us A Facebook Video Downloader For Android For #75,000 by jacob05(m): 1:36pm On Aug 07, 2015
lordZOUGA:
@Op, this is a very bad pitch. It is not clear if you are trying to attract developers or if you are trying to scare them away. I mean, it is as if you have already hired the developer in your mind and you don't trust him/her.
exactly.
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 8:08pm On Aug 06, 2015
dhtml18:
Uhm, this is a very explicit tutorial and i love it. But the problem is that I dont really understand it as it is not written in my native dialect
thanks...hmmmm...native dialect..lolx
Computer Market / Re: Thinkpad X240 Intel Core I5 4gb Ram 128gb Ssd Keyboard Light, Fingerprint 4 ~55k by jacob05(m): 9:37am On Aug 06, 2015
interested
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 11:35pm On Aug 05, 2015
Bros1:
Good job. I will advise you also put it up on codeproject.com for a wider reach.
Thanks
thanks.. I would
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 11:34pm On Aug 05, 2015
ibrodex:
GOOD job. Pyjac.... I feel you.
thanks bro !!!...same ibrodex from kp
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 4:36pm On Aug 05, 2015
updates loading
Nairaland / General / Re: A Thread For Night Crawlers. (late Sleepers) by jacob05(m): 2:09am On Aug 05, 2015
romme2u:
come on o ye crawlers for the time have ol pas grin

sleeknick where art thouest
hmmmm
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 6:33pm On Aug 04, 2015
Pffft:
Nice... I'm not a fan of too many Asserts in a method sha, also don't like d idea of try catch. I think it should have its own test with an attribute as against a try catch. Just my thoughts, anyway there are many roads into a market. Keep it coming bro
valid points.... I'm not a fan of try ...catch too..I've thought about it while writing the tutorial and thanks for pointing it out again.. but the test is actually intensional and It's meant to be discussed on later....wink
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 4:59pm On Aug 04, 2015
UPDATES LOADED... LOADING MORE LATER.. but i need your responses
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 4:58pm On Aug 04, 2015
Updated: 10/08/2015 11:43
BEGINNING TESTS: TESTING ADDITION OF ORDINARY FRACTIONS
For Addition Tests, Let’s Create a new Test Method Named testOrdinaryFractionsAdditions

[TestMethod]
public void testOrdinaryFractionsAdditions()
{

}

There are two ways we can implement this in C#
1) Using method
2) Using Operator Overloading
Hmmmm.. Lets Implement Both in Parallel !!!.
Rename testOrdinaryFractionsAdditions to testOrdinaryFractionsAdditionsUsingMethod and Add a new Test Method Named testOrdinaryFractionsAdditionsUsingOpOverloading
Now let’s write a test for Addition Using Method.Let’s write how the interface would look like then make it compile

[TestMethod]
public void testOrdinaryFractionsAdditionsUsingMethod()
{
Fraction firstFraction = new Fraction(5,10);
Fraction secondFraction = new Fraction(3,9);
Fraction result = firstFraction.Add(secondFraction);

Assert.AreEqual(75, result.Numerator);
Assert.AreEqual(90, result.Denominator);


}




Notice the Red wiggly Line under firstFraction.Add .

[img]http:///a/img912/2290/YSFEGL.jpg[/img]

That’s because it’s not yet Implemented. Click on the Add method, Hover the Little blue line under it then click Generate Method Stub.
Update the generated Add Method in Fraction.cs to

public Fraction Add(Fraction secondFraction)
{
return new Fraction(75, 90);
}

Question: Oga Jacobu, Why did you just return a Fraction object like that without any calculation or something?
Answer: That’s TDD for you, you write test progressively in simple baby steps to just pass the current test. Then later we write another test that would prompt the correction of the logic. Simple huh ?
Now, Let’s run the test and ensure we pass it .

Yup !!! Test passed

Next, Let’s Update testOrdinaryFractionsAdditionsUsingMethod to test for Another Pair of Fractions.

[TestMethod]
public void testOrdinaryFractionsAdditionsUsingMethod()
{
Fraction firstFraction = new Fraction(5,10);
Fraction secondFraction = new Fraction(3,9);
Fraction result = firstFraction.Add(secondFraction);

Assert.AreEqual(75, result.Numerator);
Assert.AreEqual(90, result.Denominator);

firstFraction = new Fraction(6, 10);
secondFraction = new Fraction(7, 20);
result = firstFraction.Add(secondFraction);

Assert.AreEqual(50, result.Numerator);
Assert.AreEqual(200, result.Denominator);


}



Run the Test Again.. It should fail.
Yep, It does. With Message : Expected<50> .Actual<75>
[img]http:///a/img537/9666/usAS97.jpg[/img]

It Failed because, for our previous test to pass, we just returned a new Fraction object in the Add Method with the values we expected.
Now, Let’s Implement the Calculation from the Logic Discussed Earlier.
Update Add Method to

public Fraction Add(Fraction secondFraction)
{
int newNumerator = (this.Numerator * secondFraction.Denominator) +
(secondFraction.Numerator * this.Denominator);
int newDenominator = this.Denominator * secondFraction.Denominator;
return new Fraction(newNumerator, newDenominator);
}

Save and Run the Test File.

Passed !!!
[img]http:///a/img913/192/Ee0EqJ.jpg[/img]
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 4:44pm On Aug 04, 2015
BEGINNING TESTS: FURTHER TESTING ORDINARY FRACTION CREATION 2
So, far how test value for creation of the Ordinary Fraction objects has been quite predictable.
What if a curious user inputs 0 (zero) for either Numerator or Denominator via our constructor?
While this can be avoid by checking the input value before using them to create Fraction objects. We (I) don’t want the class to be “DEFENSELESS”. We to throw an Exception of invalid input supplied.
So, Let Amend our FractionArithmeticTests class with this

[TestClass]
public class FractionArithmeticTests
{
[TestMethod]
public void testOrdinaryFractionCreation()
{
Fraction firstFraction = new Fraction();

Assert.AreEqual(0, firstFraction.Numerator);
Assert.AreEqual(0, firstFraction.Denominator);

firstFraction = new Fraction(5,10);
Assert.AreEqual(5, firstFraction.Numerator);
Assert.AreEqual(10, firstFraction.Denominator);

firstFraction = new Fraction(10, 5);
Assert.AreEqual(10, firstFraction.Numerator);
Assert.AreEqual(5, firstFraction.Denominator);

try{

firstFraction = new Fraction(0, 1);
Assert.Fail("Shouldn't be Able to Create a Fraction with Zero Numerator"wink;

}
catch (ArgumentOutOfRangeException ex)
{

}

}
}

In the Above Test, We’re trying to Assert that Fraction class with a numerator value of 0 is not instantiate-able. We want our Fraction class to throw an Exception ArgumentOutOfRangeException . if the Object throws the Exception (ArgumentOutOfRangeException) for firstFraction = new Fraction(0, 1); then is caught, nothing is done, skips Assert.Fail("Shouldn't be Able to Create a Fraction with Zero Numerator"wink; , and passes the test. Otherwise, If Fails.
Let’s Try and run our Test Again.. (Fingers Crossed)… 
Right Click Anywhere on the FractionArthmeticTests Code ..A Dialog Appears, Click On Run Tests !!!


Congratulations    !!! Our First Failed Test
[img]http:///a/img661/1235/weV1vE.jpg[/img]

Our test failed as expected with the Message “Shouldn't be able to Create a Fraction with Zero Numerator” . Notice the Red Bar when our Test Fails and also Green when our test Pass.
These is the TDD Life Cycle

[img]http:///a/img537/6002/mhIrAv.jpg[/img]

Red: Make your test Fail by writing a failing test
Green: Make you test Pass by implementing the needful
Refactor: Make the Code Right by remove redundant codes or duplicates.
Our Next Step is to make our Test by implementing validation before values are assigned.
We do it in two ways..
1) Validating the values in the constructor before assigning it to properties
2) Validating the values while setting value in the Property
I’d go with the first, Why ?, Because I choose to …. LOLz
Ok … Lets Edit Our Fraction Class and Implement the validation of Numerator.

……
public Fraction(int numerator, int denominator)
{
// TODO: Complete member initialization
if (numerator == 0) { throw new ArgumentOutOfRangeException("Numerator Can't be Zero"wink; }
this.Numerator = numerator;
this.Denominator = denominator;
}

That Done, Let’s Run Our Test Again.

Yes !!!, Test Passed !!!
[img]http:///a/img673/6189/X7GPrz.jpg[/img]


Next, Let’s Test That Denominator can be Zero too..
Add a new try..catch Block in the testOrdinaryFractionCreation Method in FractionArithmeticTests after the previous try..catch Block

….
try
{

firstFraction = new Fraction(0, 1);
Assert.Fail("Shouldn't be able to Create a Fraction with Zero Denominator"wink;
}
catch (ArgumentOutOfRangeException ex) { }

Let’s run our Test Again..
Right Click Anywhere on the FractionArthmeticTests Code ..A Dialog Appears, Click On Run Tests !!!
Congratulobia !!!. Our Test Failed Again with the message "Shouldn't be able to Create a Fraction with Zero Denominator"

[img]http:///a/img537/7495/GADsEo.jpg[/img]

Now Let’s make our test pass by checking the denominator before assignment in the constructor
Update
Ok … Lets Edit Our Fraction Class and Implement the validation of Denominator.

……
public Fraction(int numerator, int denominator)
{
// TODO: Complete member initialization
if (numerator == 0) { throw new ArgumentOutOfRangeException("Numerator Can't be Zero"wink; }
if (denominator == 0) { throw new ArgumentOutOfRangeException("Denominator Can't be Zero"wink; }

this.Numerator = numerator;
this.Denominator = denominator;
}

Run the Test Again.
Yes, (Dancing Shokiti Bobo),(Dtml18) our test passed !!!.

[img]http:///a/img911/6486/rIbJif.jpg[/img]

That’s about it, for now, with Ordinary Fraction Creation Test. Pls let me know other tests that can be performed.
Fraction.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FractionLibrary
{
public class Fraction
{

public Fraction(int numerator, int denominator)
{
// TODO: Complete member initialization
if (numerator == 0) { throw new ArgumentOutOfRangeException("Numerator Can't be Zero"wink; }
if (denominator == 0) { throw new ArgumentOutOfRangeException("Denominator Can't be Zero"wink; }

this.Numerator = numerator;
this.Denominator = denominator;
}

public Fraction()
{
// TODO: Complete member initialization
}

public int Numerator
{
get;
set;
}

public int Denominator
{
get;
set;

}
}
}



FractionArithmeticTests.cs

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

using FractionLibrary;

namespace FractionTest
{
[TestClass]
public class FractionArithmeticTests
{
[TestMethod]
public void testOrdinaryFractionCreation()
{
Fraction firstFraction = new Fraction();

Assert.AreEqual(0, firstFraction.Numerator);
Assert.AreEqual(0, firstFraction.Denominator);

firstFraction = new Fraction(5,10);
Assert.AreEqual(5, firstFraction.Numerator);
Assert.AreEqual(10, firstFraction.Denominator);

firstFraction = new Fraction(10, 5);
Assert.AreEqual(10, firstFraction.Numerator);
Assert.AreEqual(5, firstFraction.Denominator);

try{

firstFraction = new Fraction(0, 1);
Assert.Fail("Shouldn't be able to Create a Fraction with Zero Numerator"wink;
}
catch (ArgumentOutOfRangeException ex){}

try
{

firstFraction = new Fraction(1, 0);
Assert.Fail("Shouldn't be able to Create a Fraction with Zero Denominator"wink;
}
catch (ArgumentOutOfRangeException ex) { }


}
}
}
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 4:29pm On Aug 04, 2015
Viewing this topic: lordZOUGA(m) ... hi boss grin grin .. waiting to hear from you
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 4:19pm On Aug 04, 2015
[sup][/sup] BEGINNING TESTS: FURTHER TESTING ORDINARY FRACTION CREATION
Test Cycle
1. Add a little test
2. Run all tests and fail
3. Make a little change
4. Run the tests and succeed
5. Refactor to remove duplication
Now, Test Further …
Let’s Test our Super Fraction class by creating a new Fraction with Numerator of 5 and Denominator of 10 These we want to pass to the Fraction Class Constructor.
Update testOrdinaryFractionCreation method

public void testOrdinaryFractionCreation()
{
Fraction firstFraction = new Fraction();

Assert.AreEqual(0, firstFraction.Numerator);
Assert.AreEqual(0, firstFraction.Denominator);

firstFraction = new Fraction(5,10);
Assert.AreEqual(5, firstFraction.Numerator);
Assert.AreEqual(6, firstFraction.Denominator);
}

Notice the Red wiggly line.
[img]http:///a/img661/2473/CWO9ag.jpg[/img]
Our Tests won’t run until with fix or implement the construct.
Click on the Fraction(5,10) , Hover the Little blue line under it then click Generate Stub.. Amend the Generated Stub so that we have

public class Fraction
{

public Fraction(int numerator, int denominator)
{
// TODO: Complete member initialization
this.Numerator = numerator;
this.Denominator = denominator;
}

public int Numerator { get; set; }

public int Denominator { get; set; }
}

But Notice we still have Another Error .. Red wiggly line under new Fraction()

[img]http:///a/img901/472/FxGxuQ.jpg[/img]

With Error Message
[img]http:///a/img673/3497/CAlB6A.jpg[/img]
This is because of the new Constructor we’ve just create. If a class has no constructor , “C#” creates an empty constructor for us. but if any constructor is declared, it does not create it. In our case, we need to create another constructor that accepts no value. Let’s Go There !!!
So, like before, Click on the Fraction() , Hover the Little blue line under it then click Generate Stub..
Our Fraction.cs class now

public class Fraction
{

public Fraction(int numerator, int denominator)
{
// TODO: Complete member initialization
this.Numerator = numerator;
this.Denominator = denominator;
}

public Fraction()
{
// TODO: Complete member initialization
}

public int Numerator { get; set; }

public int Denominator { get; set; }
}

Visual Studio Should bug you again.
Right Click Anywhere on the FractionArthmeticTests Code , A Dialog Appears, Click On Run Tests !!! Our code Should work and build successfully passing the test.
Note: We haven’t had any failed test yet.. well that’s because C# has been helpful defaulting new properties to 0 (in the case of creating new empty Fraction) and we’ve not really done much.
You can test Further with new values

public class FractionArithmeticTests
{
[TestMethod]
public void testOrdinaryFractionCreation()
{
Fraction firstFraction = new Fraction();

Assert.AreEqual(0, firstFraction.Numerator);
Assert.AreEqual(0, firstFraction.Denominator);

firstFraction = new Fraction(5,10);
Assert.AreEqual(5, firstFraction.Numerator);
Assert.AreEqual(10, firstFraction.Denominator);

firstFraction = new Fraction(10, 5);
Assert.AreEqual(10, firstFraction.Numerator);
Assert.AreEqual(5, firstFraction.Denominator);
}
}
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 4:04pm On Aug 04, 2015
Fixed Wrong Images placements
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 3:53pm On Aug 04, 2015
BEGINNING TESTS

Now our project is ready for Development.

Question: What should we test?
Test (To Me) should be done on behaviours (methods) in our apps that returns a result that of value for us to pass our acceptance test.

Going to Our Requirements, we to create Fractions that can be used for Arithmetic operations.

Why not begin with testing for proper creation of ordinary Fraction Objects?
Let’s Go back to Visual Studio.
1) Rename the Generated Class UnitTest1.cs in our Unit Test Project to FractionArithmeticTests.cs and the Class name to FractionArithmeticTests (if not Refactor-ed automatically)
2) Open FractionArithmeticTests.cs and add a new method named testOrdinaryFractionCreation with [TestMethod] Decorator
Our Class, FractionArithmeticTests.cs , Should Look like this

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

namespace FractionTest
{
[TestClass]
public class FractionArithmeticTests
{
[TestMethod]
public void testOrdinaryFractionCreation()
{
}
}
}







“ When we write a test, we imagine the perfect interface for our operation. We are telling ourselves a story about how the operation will look from the outside. Our story won’t always come true, but better to start from the best possible API and work backwards than to make things complicated, ugly, and “realistic” from the get go.”

When writing test, we write how we want our class interface to look like without necessarily creating them yet.
Going back to Code.

[TestMethod]
public void testOrdinaryFractionCreation()
{
Fraction firstFraction = new Fraction();
Assert.AreEqual(0, firstFraction.Numerator);
Assert.AreEqual(0, firstFraction.Denominator);
}


[img]http:///a/img661/7277/37fGW0.jpg[/img]

Question: But Wait ooo. Oga Jacobu. Are you ok? How can we test a Class that doesn’t exist yet?
Answer: That’s the plan !!! Welcome to TDD. We’re writing how our Class objects interface should look like before writing the actual Class. We always write Tests at first that won’t compile (Notice the Red wiggly line under Fraction Class). Then we make it compile. After which our test library Asserts it False then we make it Pass !!!..
Our Next Step now is to make our App Compile by Creating the Class and implementing the property.
1) Right Click On FractionLibrary in the Solution Explorer -> Add -> Click Class

[img]http:///a/img912/9877/bIjhou.jpg[/img]


2) Name the Class Fraction.cs
[img]http:///a/img910/696/avIp7z.jpg[/img]
We have (Note Make the Class Public)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FractionLibrary
{
public class Fraction
{
}
}


3) Next You’d Observe the Red wiggly isn’t gone yet. This is because our Fraction Class is Another Project and namespace. We need to add a Reference to the FractionLibrary Project in our Fraction Project.
4) Right Click On References under FractionTest project in the Solution Explorer -> Click Add Reference

[img]http:///a/img540/3117/lJm6qK.jpg[/img]
5) Check FractionLibrary in the list. Click Ok
[img]http:///a/img673/8473/i6Kz3a.jpg[/img]
6) Update FractionArthmeticTests.cs by adding using FractionLibrary;
Our FractionArthmeticTests.cs Class now

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

using FractionLibrary;

namespace FractionTest
{
[TestClass]
public class FractionArithmeticTests
{
[TestMethod]
public void testOrdinaryFractionCreation()
{
Fraction firstFraction = new Fraction();

Assert.AreEqual(0, firstFraction.Numerator);
Assert.AreEqual(0, firstFraction.Denominator);
}
}
}


But We Still Can’t Compile Yet Because the Two Properties Numerator and Denominator are not declared in our class.
[img]http:///a/img537/2171/6Lpl68.jpg[/img]
7) Let’s Add them …. Update Fraction.cs .. Note you can use Visual Studio’s Generate Stub to Quick Add missing methods or properties… Click on the Property, Hover the Little blue line under it then click Generate Stub
[img]http:///a/img633/5951/YguFhq.jpg[/img]
Repeat for Denominator too.

….
public class Fraction
{

public int Numerator { get; set; }

public int Denominator { get; set; }
}

cool Our Project Should build in peace now !!!... Right Click Anywhere on the FractionArthmeticTests Code ..A Dialog Appears, Click On Run Tests !!!
[img]http:///a/img537/4129/wU1Qiv.jpg[/img]
9) Congratulations !!! We’ve just Passed a Test
[img]http:///a/img910/1765/RBAA9O.jpg[/img]
Programming / Re: How Can I Create A Virus Or Malware? by jacob05(m): 9:00am On Aug 04, 2015
DonSegmond:
You are not a programmer. You are an idiot. Of all things you could make, why would you want to make a virus or trojan? Are you done making video games or other fun things?
Lolz... A very valid point expressed in a very wrong manner

1 Like

Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 8:58am On Aug 04, 2015
Pffft:
Following.... Lets see your first Test
Thanks for following. hope make the much needed contribution I require.

I'd post the major tests today once I get my internet sub fixed..
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 7:51am On Aug 04, 2015
valonsoft:
Good work, Bro
Thanks...
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 6:32am On Aug 03, 2015
Updates coming soon
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 3:25pm On Aug 02, 2015
PROJECT SETUP
For this Tutorial, You’d need Microsoft Visual Studio (Express, Professional, Ultimate ) installed on your system. Once installed , with Visual C# included, we can proceed.
Our Solution Layout

We’d create three separate projects in our solution.
1) FractionConsoleApp : Contains our Console App
2) FractionLibrary : Contains our App Classes
3) FractionTest : Contains our Test Classes

So, to begin, Launch Visual Studio.

1) Select File -> New -> Project

[img]http:///a/img537/5614/lCECS0.jpg[/img]

Select Visual C# from Templates in the Left Pane; Choose Console Application in the Center Pane. For Project Name: FractionConsoleApp and Solution name: FractionArithmeticApp . Click Ok

[img]http:///a/img910/7241/FMXTx6.jpg[/img]

Our newly Created Solution
[img]http:///a/img901/7421/OeR4lw.jpg[/img]

2) Next, Right Click on the Solution Name -> Add -> Click New Project

[img]http:///a/img673/1190/otu4r1.jpg[/img]

3) Choose Class Library in the Center pane; For Project Name: FractionLibrary .Click Ok

[img]http:///a/img913/2198/QGyT6z.jpg[/img]

Repeat Step (4), Select Test in Left pane and Select Unit Test Project in the Center pane; For Project Name: FractionTest .Click Ok

[img]http:///a/img901/9225/J6MDMM.jpg[/img]

4) Our Solution’s Structure should look like this

[img]http:///a/img673/2589/kF2TFl.jpg[/img]
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 12:11pm On Aug 02, 2015
Contributions pls?

1 Like

(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) (11) (12) (of 37 pages)

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 141
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.