GY-63_MS5611/libraries/Fraction/examples/fractionTest01/fractionTest01.ino

182 lines
2.6 KiB
Arduino
Raw Normal View History

//
// FILE: fractionTest01.ino
// AUTHOR: Rob Tillaart
2021-11-01 10:56:22 -04:00
// VERSION: 0.1.2
// PURPOSE: test sketch for fraction math
2020-11-27 05:16:22 -05:00
// DATE: 2015-01-25
// URL: https://github.com/RobTillaart/Fraction
//
2021-11-01 10:56:22 -04:00
#include "fraction.h"
2021-11-01 10:56:22 -04:00
Fraction q(0.42);
Fraction a(1, 3);
Fraction aa(3, 9);
Fraction b(1, 4);
Fraction n(0, 5);
2021-01-29 06:31:58 -05:00
Fraction p(5, 1);
Fraction pi(PI);
2020-11-27 05:16:22 -05:00
Fraction e(EULER);
2021-11-01 10:56:22 -04:00
void setup()
{
Serial.begin(115200);
Serial.print("Start fractionTest: ");
2021-11-01 10:56:22 -04:00
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);
2020-11-27 05:16:22 -05:00
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();
}
2021-11-01 10:56:22 -04:00
void loop()
{
}
2021-11-01 10:56:22 -04:00
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();
}
2021-11-01 10:56:22 -04:00
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();
}
2021-11-01 10:56:22 -04:00
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();
}
2021-11-01 10:56:22 -04:00
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();
}
2021-11-01 10:56:22 -04:00
void testNEQ()
{
Serial.println("testNEQ 1 0 0");
Serial.println(a != b);
Serial.println(a != a);
Serial.println(a != aa);
Serial.println();
Serial.println();
}
2021-11-01 10:56:22 -04:00
void testLS()
{
Serial.println("testLS 0 0");
Serial.println(a < b);
Serial.println(a < a);
Serial.println();
Serial.println();
}
2021-11-01 10:56:22 -04:00
void testLE()
{
Serial.println("testLE 0 1");
Serial.println(a <= b);
Serial.println(a <= a);
Serial.println();
Serial.println();
}
2021-11-01 10:56:22 -04:00
void testGR()
{
Serial.println("testGR 1 0");
Serial.println(a > b);
Serial.println(a > a);
Serial.println();
Serial.println();
}
2021-11-01 10:56:22 -04:00
void testGE()
{
Serial.println("testGE 1 1");
Serial.println(a >= b);
Serial.println(a >= a);
Serial.println();
Serial.println();
}
2021-11-01 10:56:22 -04:00
// -- END OF FILE --