Fraction_Test.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * Created by Oliver on 16.03.2016.
  3. */
  4. import { Fraction } from "../../../src/Common/DataObjects/Fraction";
  5. describe("Fraction Unit Tests:", () => {
  6. describe("Construct Fraction, check properties", () => {
  7. const f1: Fraction = new Fraction(2, 6);
  8. it("Numerator and Denominator", (done: Mocha.Done) => {
  9. chai.expect(f1.Numerator).to.equal(1);
  10. chai.expect(f1.Denominator).to.equal(3);
  11. done();
  12. });
  13. it("Real value", (done: Mocha.Done) => {
  14. chai.expect(f1.RealValue).to.equal(1 / 3);
  15. done();
  16. });
  17. });
  18. describe("Compare fractions", () => {
  19. let f1: Fraction;
  20. let f2: Fraction;
  21. const rand: () => number = function(): number {
  22. return Math.floor(Math.random() * 500) + 1;
  23. };
  24. it("lt attribute", (done: Mocha.Done) => {
  25. for (let i: number = 0; i < 10; i += 1) {
  26. f1 = new Fraction(rand(), rand());
  27. f2 = new Fraction(rand(), rand());
  28. chai.expect(f1.lt(f2)).to.equal(f1.RealValue < f2.RealValue);
  29. }
  30. done();
  31. });
  32. });
  33. });