git @ Cat's Eye Technologies Samovar / add-tests
Deterministic operation, Falderal tests and test-running script. Chris Pressey 6 years ago
3 changed file(s) with 150 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
33 """\
44 samovar {option} input.samovar
55
6 Driver script for Samovr assertion-retraction engine.
6 Driver script for Samovar assertion-retraction engine.
77 """
88
99 from os.path import realpath, dirname, join
1313
1414 import codecs
1515 from optparse import OptionParser
16 import random
1617
1718 from samovar.parser import Parser
1819 from samovar.generator import Generator
3031 optparser.add_option("--length",
3132 type=int, default=0,
3233 help="If given, generate this many events for each situation")
34 optparser.add_option("--line-per-sentence",
35 action="store_true")
36 optparser.add_option("--seed",
37 type=int, default=None,
38 help="Set random seed (to select moves deterministically)")
3339 optparser.add_option("--words",
3440 type=int, default=0,
3541 help="If given, generate each situation til this many words")
4551 if options.dump_ast:
4652 print ast
4753 sys.exit(0)
54 if options.seed is not None:
55 random.seed(options.seed)
4856 g = Generator(ast, debug=options.debug)
4957 if options.length > 0:
5058 events = g.generate_events(options.length)
5159 elif options.words > 0:
5260 events = g.generate_words(options.words)
5361 for e in events:
54 sys.stdout.write("%s " % e)
62 if options.line_per_sentence:
63 sys.stdout.write("%s\n" % e)
64 else:
65 sys.stdout.write("%s " % e)
5566 sys.stdout.write("\n")
0 Samovar
1 =======
2
3 This is a literate test suite for Samovar, in Falderal format.
4 It describes Samovar, and includes examples inline; each example
5 specifies the expected result of running it, so these examples
6 can be run as tests. (That's what Falderal does.)
7
8 -> Tests for functionality "Run Samovar Simulation"
9
10 -> Functionality "Run Samovar Simulation" is implemented by
11 -> shell command
12 -> "bin/samovar %(test-body-file) --words 20 --line-per-sentence --seed 0"
13
14 Ignatz
15 ------
16
17 rules
18 [actor(α),item(β),~holding(α,β)] α picks up the β. [holding(α,β)]
19 [actor(α),item(β),holding(α,β)] α puts down the β. [~holding(α,β)]
20 end
21 situations
22 [actor(Ignatz),item(brick)]
23 end
24
25 ===> Ignatz picks up the brick.
26 ===> Ignatz puts down the brick.
27 ===> Ignatz picks up the brick.
28 ===> Ignatz puts down the brick.
29
30
31 chairs
32 ------
33
34 rules
35
36 [actor(ρ),~sitting(ρ)]
37 ρ walks around the room.
38 []
39
40 [actor(ρ),~sitting(ρ),nearby(κ),empty(κ)]
41 ρ sits down in the κ.
42 [sitting(ρ),in(ρ,κ),~empty(κ)]
43
44 [actor(ρ),sitting(ρ),in(ρ,κ)]
45 ρ leans back in the κ.
46 []
47
48 [actor(ρ),sitting(ρ),in(ρ,κ)]
49 ρ gets up and stretches.
50 [~sitting(ρ),~in(ρ,κ),empty(κ)]
51
52 end
53
54 situations
55
56 [
57 actor(Hastings),
58 actor(Petersen),
59 actor(Wembley),
60 nearby(chair), empty(chair),
61 nearby(recliner), empty(recliner),
62 nearby(sofa), empty(sofa)
63 ]
64
65 end
66 ===> Hastings sits down in the chair.
67 ===> Hastings leans back in the chair.
68 ===> Wembley sits down in the recliner.
69 ===> Petersen sits down in the sofa.
70
71 idle
72 ----
73
74 rules
75
76 [actor(ρ)]
77 ρ rubs his chin.
78 []
79
80 [actor(ρ)]
81 ρ yawns.
82 []
83
84 end
85 ???> IndexError
86
87 functions
88 ---------
89
90 rules
91 [actor(ρ)]
92 ρ scratches their(ρ) head.
93 []
94 end
95 functions
96 their(Alice) → her
97 their(Bob) → his
98 end
99 situations
100 [
101 actor(Alice),
102 actor(Bob)
103 ]
104 end
105
106 ===> Alice scratches her head.
107 ===> Alice scratches her head.
108 ===> Bob scratches his head.
109 ===> Bob scratches his head.
110 ===> Alice scratches her head.
111
112 no need for functions
113 ---------------------
114
115 rules
116 [actor(ρ),possessive(ρ,ξ)]
117 ρ scratches ξ head.
118 []
119 end
120 situations
121 [
122 actor(Alice),
123 possessive(Alice, her),
124 actor(Bob),
125 possessive(Bob, his)
126 ]
127 end
128
129 ===> Alice scratches her head.
130 ===> Alice scratches her head.
131 ===> Bob scratches his head.
132 ===> Bob scratches his head.
133 ===> Alice scratches her head.
0 #!/bin/sh
1
2 falderal -b doc/Samovar.md || exit 1