/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using VQDR.Expression;
using GLib;

void d6_test () {
   
    Test.add_func ("/VQDR/Expression/Dice/d6/to_string1", () => {
      Dice d = new Dice ();
      if (!(d.to_string () == "1d6")) {
        Test.fail ();
        Test.message ("The string does not match the expected value.");
      }
    });
    
    Test.add_func ("/VQDR/Expression/Dice/d6/to_string2", () => {
      Dice d = new Dice (5,6);
      if (!(d.to_string () == "5d6")) {
        Test.fail ();
        Test.message ("The string does not match the expected value.");
      }
    });
    
    Test.add_func ("/VQDR/Expression/Dice/d6/to_string3", () => {
      Dice d = new Dice (1,6,4);
      if (!(d.to_string () == "1d6+4")) {
        Test.fail ();
        Test.message ("The string does not match the expected value.");
      }
    });
    
    Test.add_func ("/VQDR/Expression/Dice/d6/to_string4", () => {
      Dice d = new Dice (1,6,-4);
      if (!(d.to_string () == "1d6-4")) {
        Test.fail ();
        Test.message ("The string does not match the expected value.");
      }
    });
    
    Test.add_func ("/VQDR/Expression/Dice/d6/roll_count", () => {
      Dice d = new Dice ();
      int32 count[7] = {0};
      int32 rolls = 1000000;
      for (size_t i = 0; i < rolls; i++) {
        uint32 r = d.roll ();
        
        count[r] += 1;
      }
      int32 total = 0;
      for (int32 i = 0; i < 6; i++) {
        total += count[i];
      }
      
      if (!(total == rolls)) {
        Test.fail ();
        Test.message ("Rolles do not add up.");
      }
    });
    
    Test.add_func ("/VQDR/Expression/Dice/d6/roll_probability", () => {
      Dice d = new Dice ();
      int32 count[7] = {0};
      int32 rolls = 1000000;
      for (size_t i = 0; i < rolls; i++) {
        uint32 r = d.roll ();
        
        count[r] += 1;
      }
      for (int32 i = 0; i < 6; i++) {
        print ("------------\n");
        print ("count for %d : %\n", i + 1, count[i] );
        double procentile = ((double )count[i] / rolls) * 100;
        if ((procentile < 15) || (procentile > 17)) {
          // The value sholud be aronud 16 %
          Test.message ("Procentile of D6 is off. Expected close to 16 %% got %f", procentile);
          Test.fail ();
        }
        print ("chance for %d : %f %%\n", i, procentile );
      }
    
    });
}