/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/random-d6.vala

  • Committer: Gustav Hartvigsson
  • Date: 2020-06-07 18:48:24 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20200607184824-jf14f7a1b1di2i2q
* Initial code - far from done

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 ();
 
40
      int count[7] = {0};
 
41
      int rolls = 1000000;
 
42
      for (size_t i = 0; i < rolls; i++) {
 
43
        int r = d.roll ();
 
44
        
 
45
        count[r] += 1;
 
46
      }
 
47
      int total = 0;
 
48
      for (int i = 0; i < 6; i++) {
 
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 ();
 
60
      int count[7] = {0};
 
61
      int rolls = 1000000;
 
62
      for (size_t i = 0; i < rolls; i++) {
 
63
        int r = d.roll ();
 
64
        
 
65
        count[r] += 1;
 
66
      }
 
67
      for (int i = 0; i < 6; i++) {
 
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
}