/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk
1 by Gustav Hartvigsson
* Initial code - far from done
1
using VQDR.Expression;
2
using GLib;
3
4
void d6_test () {
5
   
6
    Test.add_func ("/VQDR/Expression/Dice/d6/to_string1", () => {
7
      Dice d = new Dice ();
8
      if (!(d.to_string () == "1d6")) {
9
        Test.fail ();
10
        Test.message ("The string does not match the expected value.");
11
      }
12
    });
13
    
14
    Test.add_func ("/VQDR/Expression/Dice/d6/to_string2", () => {
15
      Dice d = new Dice (5,6);
16
      if (!(d.to_string () == "5d6")) {
17
        Test.fail ();
18
        Test.message ("The string does not match the expected value.");
19
      }
20
    });
21
    
22
    Test.add_func ("/VQDR/Expression/Dice/d6/to_string3", () => {
23
      Dice d = new Dice (1,6,4);
24
      if (!(d.to_string () == "1d6+4")) {
25
        Test.fail ();
26
        Test.message ("The string does not match the expected value.");
27
      }
28
    });
29
    
30
    Test.add_func ("/VQDR/Expression/Dice/d6/to_string4", () => {
31
      Dice d = new Dice (1,6,-4);
32
      if (!(d.to_string () == "1d6-4")) {
33
        Test.fail ();
34
        Test.message ("The string does not match the expected value.");
35
      }
36
    });
37
    
38
    Test.add_func ("/VQDR/Expression/Dice/d6/roll_count", () => {
39
      Dice d = new Dice ();
52.1.3 by Gustav Hartvigsson
int -> int32
40
      int32 count[7] = {0};
41
      int32 rolls = 1000000;
1 by Gustav Hartvigsson
* Initial code - far from done
42
      for (size_t i = 0; i < rolls; i++) {
60 by Gustav Hartvigsson
Added int32_abs () to Utils.
43
        uint32 r = d.roll ();
1 by Gustav Hartvigsson
* Initial code - far from done
44
        
45
        count[r] += 1;
46
      }
52.1.3 by Gustav Hartvigsson
int -> int32
47
      int32 total = 0;
48
      for (int32 i = 0; i < 6; i++) {
1 by Gustav Hartvigsson
* Initial code - far from done
49
        total += count[i];
50
      }
51
      
52
      if (!(total == rolls)) {
53
        Test.fail ();
54
        Test.message ("Rolles do not add up.");
55
      }
56
    });
57
    
58
    Test.add_func ("/VQDR/Expression/Dice/d6/roll_probability", () => {
59
      Dice d = new Dice ();
52.1.3 by Gustav Hartvigsson
int -> int32
60
      int32 count[7] = {0};
61
      int32 rolls = 1000000;
1 by Gustav Hartvigsson
* Initial code - far from done
62
      for (size_t i = 0; i < rolls; i++) {
60 by Gustav Hartvigsson
Added int32_abs () to Utils.
63
        uint32 r = d.roll ();
1 by Gustav Hartvigsson
* Initial code - far from done
64
        
65
        count[r] += 1;
66
      }
52.1.3 by Gustav Hartvigsson
int -> int32
67
      for (int32 i = 0; i < 6; i++) {
1 by Gustav Hartvigsson
* Initial code - far from done
68
        print ("------------\n");
69
        print ("count for %d : %\n", i + 1, count[i] );
70
        double procentile = ((double )count[i] / rolls) * 100;
71
        if ((procentile < 15) || (procentile > 17)) {
72
          // The value sholud be aronud 16 %
73
          Test.message ("Procentile of D6 is off. Expected close to 16 %% got %f", procentile);
74
          Test.fail ();
75
        }
76
        print ("chance for %d : %f %%\n", i, procentile );
77
      }
78
    
79
    });
80
}