Fraction_Test.ts 1.2 KB

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