/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk

« back to all changes in this revision

Viewing changes to tests/fast_number.vala

  • Committer: Gustav Hartvigsson
  • Date: 2021-09-09 12:57:20 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210909125720-x6t14nri2anelxp6
Added Round Up and Round Down function classes.
Added ronud up and round down operations to FastNumbers to facitilate this.

TODO: Write tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using GLib;
 
2
 
 
3
using VQDR.Common.Utils;
 
4
using VQDR.Common;
 
5
using VQDR.Expression;
 
6
 
 
7
void fast_number_test () {
 
8
  Test.add_func ("/Common/Utils/FastNumber/add", () => {
 
9
    var f1 = FastNumber (1337);
 
10
    var f2 = FastNumber (1333);
 
11
    var f3 = f1.add (f2);
 
12
    if (f3.number != 2670) {
 
13
      Test.fail ();
 
14
      Test.message ("The added numbers do not match the expected value");
 
15
    }
 
16
  });
 
17
  Test.add_func ("/Common/Utils/FastNumber/subtract", () => {
 
18
    var f1 = FastNumber (1337);
 
19
    var f2 = FastNumber (1333);
 
20
    var f3 = f1.subtract (f2);
 
21
    if (f3.number != 4) {
 
22
      Test.fail ();
 
23
      Test.message ("The subtracted numbers do not match the expected value");
 
24
    }
 
25
  });
 
26
  Test.add_func ("/Common/Utils/FastNumber/divide", () => {
 
27
    var f1 = FastNumber (1338);
 
28
    var f2 = FastNumber (2);
 
29
    FastNumber f3 = {0};
 
30
    try {
 
31
      f3 = f1.divide (f2);
 
32
      Utils.print_ln ("f3.number: %i", f3.number);
 
33
    } catch (Error e) {
 
34
      Utils.print_ln ("Error: %s\n", e.message);
 
35
    }
 
36
    if (f3.number != 669) {
 
37
      Test.fail ();
 
38
      Test.message ("The added numbers do not match the expected value");
 
39
    }
 
40
  });
 
41
  
 
42
  Test.add_func ("/Common/Utils/FastNumber/divide2", () => {
 
43
    var f1 = FastNumber (4444);
 
44
    var f2 = FastNumber (1111);
 
45
    FastNumber f3 = {0};
 
46
    try {
 
47
      f3 = f1.divide (f2);
 
48
      Utils.print_ln ("f3.number: %i", f3.number);
 
49
    } catch (Error e) {
 
50
      Utils.print_ln ("Error: %s\n", e.message);
 
51
    }
 
52
    if (f3.number != 4) {
 
53
      Test.fail ();
 
54
      Test.message ("The added numbers do not match the expected value");
 
55
    }
 
56
  });
 
57
  
 
58
  Test.add_func ("/Common/Utils/FastNumber/multiply", () => {
 
59
    
 
60
  });
 
61
}