mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
182 lines
2.6 KiB
C++
182 lines
2.6 KiB
C++
//
|
|
// FILE: fractionTest01.ino
|
|
// AUTHOR: Rob Tillaart
|
|
// VERSION: 0.1.2
|
|
// PURPOSE: test sketch for fraction math
|
|
// DATE: 2015-01-25
|
|
// URL: https://github.com/RobTillaart/Fraction
|
|
//
|
|
|
|
|
|
#include "fraction.h"
|
|
|
|
|
|
Fraction q(0.42);
|
|
Fraction a(1, 3);
|
|
Fraction aa(3, 9);
|
|
Fraction b(1, 4);
|
|
Fraction n(0, 5);
|
|
Fraction p(5, 1);
|
|
Fraction pi(PI);
|
|
Fraction e(EULER);
|
|
|
|
|
|
void setup()
|
|
{
|
|
Serial.begin(115200);
|
|
Serial.print("Start fractionTest: ");
|
|
Serial.println(FRACTION_LIB_VERSION);
|
|
Serial.println();
|
|
|
|
Serial.println(a);
|
|
Serial.println(aa);
|
|
Serial.println(b);
|
|
Serial.println(n);
|
|
Serial.println(p);
|
|
Serial.println(q);
|
|
Serial.println(pi);
|
|
Serial.println(e);
|
|
Serial.println(Fraction::middle(pi, e));
|
|
Serial.println(Fraction::mediant(pi, e));
|
|
Serial.println();
|
|
|
|
testPlus();
|
|
testMin();
|
|
testMul();
|
|
testDiv();
|
|
|
|
testEQ();
|
|
testNEQ();
|
|
testLS();
|
|
testLE();
|
|
testGR();
|
|
testGE();
|
|
}
|
|
|
|
|
|
void loop()
|
|
{
|
|
}
|
|
|
|
|
|
void testPlus()
|
|
{
|
|
Serial.println("testPlus");
|
|
Serial.println(a + b);
|
|
Fraction c = a + b;
|
|
Serial.println(c);
|
|
c = a;
|
|
c += b;
|
|
Serial.println(c);
|
|
Serial.println();
|
|
Serial.println();
|
|
}
|
|
|
|
|
|
void testMin()
|
|
{
|
|
Serial.println("testMin");
|
|
Serial.println(a - b);
|
|
Fraction c = a - b;
|
|
Serial.println(c);
|
|
c = a;
|
|
c -= b;
|
|
Serial.println(c);
|
|
Serial.println();
|
|
Serial.println();
|
|
}
|
|
|
|
|
|
void testMul()
|
|
{
|
|
Serial.println("testMul");
|
|
Serial.println(a * b);
|
|
Fraction c = a * b;
|
|
Serial.println(c);
|
|
c = a;
|
|
c *= b;
|
|
Serial.println(c);
|
|
Serial.println();
|
|
Serial.println();
|
|
}
|
|
|
|
|
|
void testDiv()
|
|
{
|
|
Serial.println("testDiv");
|
|
Serial.println(a / b);
|
|
Fraction c = a / b;
|
|
Serial.println(c);
|
|
c = a;
|
|
c /= b;
|
|
Serial.println(c);
|
|
Serial.println();
|
|
Serial.println();
|
|
}
|
|
|
|
|
|
void testEQ()
|
|
{
|
|
Serial.println("testEQ 0 1 1");
|
|
Serial.println(a == b);
|
|
Serial.println(a == a);
|
|
Serial.println(a == aa);
|
|
Serial.println();
|
|
Serial.println();
|
|
}
|
|
|
|
|
|
void testNEQ()
|
|
{
|
|
Serial.println("testNEQ 1 0 0");
|
|
Serial.println(a != b);
|
|
Serial.println(a != a);
|
|
Serial.println(a != aa);
|
|
Serial.println();
|
|
Serial.println();
|
|
}
|
|
|
|
|
|
void testLS()
|
|
{
|
|
Serial.println("testLS 0 0");
|
|
Serial.println(a < b);
|
|
Serial.println(a < a);
|
|
Serial.println();
|
|
Serial.println();
|
|
}
|
|
|
|
|
|
void testLE()
|
|
{
|
|
Serial.println("testLE 0 1");
|
|
Serial.println(a <= b);
|
|
Serial.println(a <= a);
|
|
Serial.println();
|
|
Serial.println();
|
|
}
|
|
|
|
|
|
void testGR()
|
|
{
|
|
Serial.println("testGR 1 0");
|
|
Serial.println(a > b);
|
|
Serial.println(a > a);
|
|
Serial.println();
|
|
Serial.println();
|
|
}
|
|
|
|
|
|
void testGE()
|
|
{
|
|
Serial.println("testGE 1 1");
|
|
Serial.println(a >= b);
|
|
Serial.println(a >= a);
|
|
Serial.println();
|
|
Serial.println();
|
|
}
|
|
|
|
|
|
// -- END OF FILE --
|
|
|