Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this exercise you will be using Microsoft Unit Test framework to test a class. You must follow the specifications exactly (To demo to instructor

In this exercise you will be using Microsoft Unit Test framework to test a class.

You must follow the specifications exactly (To demo to instructor at the end of this class)

Create a library containing the Fraction class

This class consist of 6 members.

Fraction

Class

Properties

+ <>Top : int

+ <>Bottom : int

Methods

+ <> Fraction(int top = 0, int bottom = 1)

+$ <<operator>> +( Fraction left, Fraction right): Fraction

+$ <<operator>> -( Fraction left, Fraction right): Fraction

+ ToString() : string

Description of class members

Some common decorators for class members

+ public # protected - private $ class member (static)

Fields:

There are no fields

Properties:

All the properties have public getters and private setters.

Top this property represents the numerator of this object.

Bottom this property represents the denominator of this object

Constructor:

Fraction(int top = 0, int bottom = 1) This constructor takes two optional parameters and assigns them to the appropriate properties.

Operators:

There are two overloaded operators: the addition and the subtraction operators

Look at the Complex Number Lab to for hints on operator overloading

public static Fraction operator +(Fraction left, Fraction right) This will implement the addition operation.

public static Fraction operator -(Fraction left, Fraction right) This will implement the subtraction operation. This will throw an exception if the right argument is larger than the left side argument.

Methods:

public override string ToString() This is a public method overrides the corresponding method in the object class to return a stringify form of the object. You get to decide how the properties will be display to the user.

Try to keep the output on a single line.

Unit Testing

Remember in testing you will compare the expected value to the actual value. You need to write the testing methods for the following:

If you are having problems accessing your Fraction class from your testing project, or running your tests check the following:

Ensure a reference to the library is added to your testing project

Add the necessary using statement

Verify that the Fraction class is public

Confirm that you are NOT running from an unsecured drive such as the network H drive


//1 Constructor. You must test the three cases: creating a fraction with two ints, with one int and with no argument

//arrange

//declare and suitably initialise two int: expectedTop and expectedBottom

//act

//create a fraction using the above two arguments

//assert

//compare the expectedTop with the Top property of the above object

Note: To test this constructor exhaustively, you need to check three conditions: constructor with zero, one and two arguments


//compare the expectedBottom with the Bottom property of the above fraction

//2 ToString.

//arrange

//declare and initialise two ints

//declare the variable expectedString that will depend on your ToString() method.

//act

//declare and create an object using the above two ints

//assert

//compare the expectedString variable to the actual output of the ToString() method

.

You may use the following sample for your addition


//3 Addition.

You may use the following sample for your subtraction


//4 Subtraction without exception.

//5 - Subtraction with exception.

You may use the following sample for your subtraction


Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions