Engineering 3891 Assignment 8 Test Code

 


// Includes
#include "assign8.h"
#include <iostream.h>
#include <string.h>
#include <math.h>

int main()
{
cout << "-------------------------------------------------------" << endl;
cout << "Testing resistor object" << endl;
cout << "-------------------------------------------------------" << endl;
cout << "Constructing resistor R1: ";
Resistor R1(10e3, 0.05);
cout << R1.who();

if (strcmp(R1.who(), "R1") == 0)
cout << " PASS" << endl;
else
cout << " FAIL" << endl;

cout << "Value of R1 is " << R1.value() << endl;
cout << "Tolerance of R1 is " << R1.tolerance() << endl;

cout << "Constructing resistor R2: ";
Resistor R2(10e3, 0.05);
cout << R2.who();

if (strcmp(R2.who(), "R2") == 0)
cout << " PASS" << endl;
else
cout << " FAIL" << endl;


cout << "Setting pin 1 of R1 to net con 4: ";
R1[1].n = 4;
cout << R1[1].n;
if (R1[1].n == 4)
cout << " PASS" << endl;
else
cout << " FAIL" << endl;

cout << "Setting pin 2 of R1 to ground: ";
R1[2].n = 0;
cout << R1[2].n;
if (R1[2].n == 0)
cout << " PASS" << endl;
else
cout << " FAIL" << endl;

cout << "Attempting to change pin 256 of R1 to 7: ";
R1[256].n = 7;
cout << R1[256].n;
if (R1[256].n == 7)
cout << " PASS" << endl;
else
cout << " FAIL" << endl;

cout << "Testing for bidirectional inputs: ";
if (R1[1].t == BIDI && R1[2].t == BIDI)
cout << " PASS" << endl;
else
{
cout << " FAIL" << endl;
cout << "R1[1].t == " << R1[1].t << endl;
cout << "R1[2].t == " << R1[2].t << endl;
}

cout << "-------------------------------------------------------" << endl;
cout << "Testing capacitor object" << endl;
cout << "-------------------------------------------------------" << endl;
cout << "Constructing capacitor C1: ";
Capacitor C1(1e-6, CERAMIC, .05);
cout << C1.who();

if (strcmp(C1.who(), "C1") == 0)
cout << " PASS" << endl;
else
cout << " FAIL" << endl;

cout << "Testing C1 for ceramic type: " << C1.type();
if (C1.type() == 0)
cout << " PASS" << endl;
else
cout << " FAIL" << endl;

cout << "Value of C1 is " << C1.value() << endl;
cout << "Tolerance of C1 is " << C1.tolerance() << endl;

cout << "Constructing capacitor C2: ";
Capacitor C2(5e-6, ELECTROLYTIC, 0.05);
cout << C2.who();
if (strcmp(C2.who(), "C2") == 0)
cout << " PASS" << endl;
else
cout << " FAIL" << endl;

cout << "Testing C2 for electrolytic type: " << C2.type();
if (C2.type() == 1)
cout << " PASS" << endl;
else
cout << " FAIL" << endl;


cout << "Setting pin 1 of C1 to net con 4: ";
C1[1].n = 4;
cout << C1[1].n;
if (C1[1].n == 4)
cout << " PASS" << endl;
else
cout << " FAIL" << endl;

cout << "Setting pin 2 of C1 to ground: ";
C1[2].n = 0;
cout << C1[2].n;
if (C1[2].n == 0)
cout << " PASS" << endl;
else
cout << " FAIL" << endl;

cout << "Attempting to change pin 256 of C1 to 9: ";
C1[256].n = 9;
cout << C1[256].n;
if (C1[256].n == 9)
cout << " PASS" << endl;
else
cout << " FAIL" << endl;

cout << "Testing for bidirectional inputs: ";
if (C1[1].t == BIDI && C1[2].t == BIDI)
cout << " PASS" << endl;
else
{
cout << " FAIL" << endl;
cout << "C1[1].t == " << C1[1].t << endl;
cout << "C1[2].t == " << C1[2].t << endl;
}

cout << "-------------------------------------------------------" << endl;
cout << "Testing logic object" << endl;
cout << "-------------------------------------------------------" << endl;
cout << "Constructing logic gate AND U1: ";
Gate U1(AND);
cout << U1.who();
if (strcmp(U1.who(), "U1") == 0)
cout << " PASS" << endl;
else
cout << " FAIL" << endl;

cout << "Constructing logic gate OR U2: ";
Gate U2(AND);
cout << U2.who();
if (strcmp(U2.who(), "U2") == 0)
cout << " PASS" << endl;
else
cout << " FAIL" << endl;

cout << "Setting pin 1 of U1 to net con 5: ";
U1[1].n = 5;
cout << U1[1].n;
if (U1[1].n == 5)
cout << " PASS" << endl;
else
cout << " FAIL" << endl;

cout << "Setting pin 2 of U1 to ground: ";
U1[2].n = 0;
cout << U1[2].n;
if (U1[2].n == 0)
cout << " PASS" << endl;
else
cout << " FAIL" << endl;

cout << "Pin one of U1 is " << U1[1].t << endl;
cout << "Pin two of U1 is " << U1[2].t << endl;
cout << "Pin three of U1 is " << U1[3].t << endl;
if (U1[1].t == IN && U1[2].t == IN && U1[3].t == OUT)
cout << "Pins were initialized correctly - PASS" << endl;
else
cout << "Pins were NOT initialized correctly - FAIL" << endl;

return 0;
}