Skip to content

Commit 3f1b908

Browse files
authored
Merge pull request #2483 from lf-lang/ai-gen-python-test
Add new Python tests (AI-generated)
2 parents b2747eb + 53ba761 commit 3f1b908

File tree

158 files changed

+2134
-554
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+2134
-554
lines changed

test/Python/src/ActionDelay.lf

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ reactor Source {
2626
}
2727

2828
reactor Sink {
29-
input _in
29+
input inp
3030

31-
reaction(_in) {=
31+
reaction(inp) {=
3232
elapsed_logical = lf.time.logical_elapsed()
3333
logical = lf.time.logical()
3434
physical = lf.time.physical()
@@ -47,5 +47,5 @@ main reactor ActionDelay {
4747
g = new GeneratedDelay()
4848

4949
source.out -> g.y_in
50-
g.y_out -> sink._in
50+
g.y_out -> sink.inp
5151
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
target Python {
2+
timeout: 7 msecs,
3+
fast: true
4+
}
5+
6+
main reactor {
7+
logical action a
8+
logical action b
9+
10+
reaction(startup) -> a {=
11+
a.schedule(MSEC(1))
12+
=}
13+
14+
reaction(a, b) -> a, b {=
15+
if (a.is_present) :
16+
print("A", end="")
17+
b.schedule(MSEC(2))
18+
19+
if (b.is_present) :
20+
print("B", end="")
21+
a.schedule(MSEC(1))
22+
23+
24+
print(f" at {lf.time.logical_elapsed() / MSEC(1)} msecs with triggers ({a.is_present},{b.is_present})")
25+
26+
if (a.is_present and b.is_present) :
27+
lf_print_error_and_exit("Both triggers should not be present")
28+
=}
29+
}

test/Python/src/AfterCycles.lf

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ reactor Source {
1111
}
1212

1313
reactor Work {
14-
input _in
14+
input inp
1515
output out
1616

17-
reaction(_in) -> out {=
18-
out.set(_in.value)
17+
reaction(inp) -> out {=
18+
out.set(inp.value)
1919
=}
2020
}
2121

@@ -25,8 +25,8 @@ main reactor AfterCycles {
2525
w0 = new Work()
2626
w1 = new Work()
2727

28-
s.out -> w0._in after 10 msec
29-
s.out -> w1._in after 20 msec
28+
s.out -> w0.inp after 10 msec
29+
s.out -> w1.inp after 20 msec
3030

3131
reaction(w0.out) {=
3232
self.count+=1

test/Python/src/AfterZero.lf

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
target Python {
2+
fast: false,
3+
timeout: 3 sec
4+
}
5+
6+
reactor foo {
7+
input x
8+
output y
9+
10+
reaction(x) -> y {=
11+
y.set(2*x.value)
12+
=}
13+
}
14+
15+
reactor print {
16+
state expected_time = 0
17+
state received = 0
18+
input x
19+
20+
reaction(x) {=
21+
self.received+=1
22+
elapsed_time = lf.time.logical_elapsed()
23+
print("Result is " + str(x.value))
24+
if x.value != 84:
25+
sys.stderr.write("ERROR: Expected result to be 84.\n")
26+
exit(1)
27+
print("Current logical time is: " + str(elapsed_time))
28+
print("Current microstep is: " + str(lf.tag().microstep))
29+
print("Current physical time is: " + str(lf.time.physical_elapsed()))
30+
if elapsed_time != self.expected_time:
31+
sys.stderr.write("ERROR: Expected logical time to be " + str(self.expected_time) + ".\n")
32+
exit(2)
33+
if lf.tag().microstep != 1:
34+
sys.stderr.write("ERROR: Expected microstep to be 1\n")
35+
exit(3)
36+
self.expected_time += SEC(1)
37+
=}
38+
39+
reaction(shutdown) {=
40+
if self.received == 0:
41+
sys.stderr.write("ERROR: Final reactor received no data.\n")
42+
exit(3)
43+
=}
44+
}
45+
46+
main reactor {
47+
f = new foo()
48+
p = new print()
49+
timer t(0, 1 sec)
50+
f.y -> p.x after 0
51+
52+
reaction(t) -> f.x {=
53+
f.x.set(42)
54+
=}
55+
}

test/Python/src/ArrayAsParameter.lf

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ reactor Source(sequence = [0, 1, 2]) {
1515
}
1616

1717
reactor Print {
18-
input _in
18+
input inp
1919
state count = 1
2020
state received = 0
2121

22-
reaction(_in) {=
22+
reaction(inp) {=
2323
self.received+=1
24-
print("Received: {:d}\n".format(_in.value))
25-
if _in.value != self.count:
24+
print("Received: {:d}\n".format(inp.value))
25+
if inp.value != self.count:
2626
sys.stderr.write("ERROR: Expected {:d}.\n".format(self.count))
2727
exit(1)
2828
self.count+=1
@@ -38,5 +38,5 @@ reactor Print {
3838
main reactor ArrayAsParameter {
3939
s = new Source(sequence = [1, 2, 3, 4])
4040
p = new Print()
41-
s.out -> p._in
41+
s.out -> p.inp
4242
}

test/Python/src/ArrayAsType.lf

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ reactor Source {
1313

1414
# The scale parameter is just for testing.
1515
reactor Print(scale=1) {
16-
input _in
16+
input inp
1717

18-
reaction(_in) {=
19-
print("Received: [%s]" % ", ".join(map(str, _in.value)))
20-
if _in.value != (0, 2.8, "hello"):
18+
reaction(inp) {=
19+
print("Received: [%s]" % ", ".join(map(str, inp.value)))
20+
if inp.value != (0, 2.8, "hello"):
2121
sys.stderr.write("ERROR: Value received by Print does not match expectation!\n")
2222
exit(1)
2323
=}
@@ -26,5 +26,5 @@ reactor Print(scale=1) {
2626
main reactor ArrayAsType {
2727
s = new Source()
2828
p = new Print()
29-
s.out -> p._in
29+
s.out -> p.inp
3030
}

test/Python/src/ArrayFree.lf

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import Source, Print from "ArrayPrint.lf"
88
import Scale from "ArrayScale.lf"
99

1010
reactor Free(scale=2) {
11-
mutable input _in
11+
mutable input inp
1212

13-
reaction(_in) {=
14-
for i in range(len(_in.value)):
15-
_in.value[i] *= self.scale
13+
reaction(inp) {=
14+
for i in range(len(inp.value)):
15+
inp.value[i] *= self.scale
1616
=}
1717
}
1818

@@ -21,7 +21,7 @@ main reactor ArrayFree {
2121
c = new Free()
2222
c2 = new Scale()
2323
p = new Print(scale=2)
24-
s.out -> c._in
25-
s.out -> c2._in
26-
c2.out -> p._in
24+
s.out -> c.inp
25+
s.out -> c2.inp
26+
c2.out -> p.inp
2727
}

test/Python/src/ArrayFreeMultiple.lf

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
target Python
2+
3+
import Scale from "ArrayScale.lf"
4+
import Print from "ArrayPrint.lf"
5+
6+
reactor Source {
7+
output out
8+
9+
reaction(startup) -> out {=
10+
out.set([0, 1, 2])
11+
=}
12+
}
13+
14+
reactor Free(scale=2) {
15+
mutable input inp
16+
17+
reaction(inp) {=
18+
for i in range(len(inp.value)):
19+
inp.value[i] *= self.scale
20+
=}
21+
}
22+
23+
main reactor ArrayFreeMultiple {
24+
s = new Source()
25+
c = new Free()
26+
c2 = new Scale()
27+
p = new Print(scale=2)
28+
s.out -> c.inp
29+
s.out -> c2.inp
30+
c2.out -> p.inp
31+
}

test/Python/src/ArrayParallel.lf

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ main reactor ArrayParallel {
1212
c2 = new Scale(scale=3)
1313
p1 = new Print(scale=2)
1414
p2 = new Print(scale=3)
15-
s.out -> c1._in
16-
s.out -> c2._in
17-
c1.out -> p1._in
18-
c2.out -> p2._in
15+
s.out -> c1.inp
16+
s.out -> c2.inp
17+
c1.out -> p1.inp
18+
c2.out -> p2.inp
1919
}

test/Python/src/ArrayPrint.lf

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ reactor Source {
1313

1414
# The scale parameter is just for testing.
1515
reactor Print(scale=1) {
16-
input _in
16+
input inp
1717

18-
reaction(_in) {=
19-
print("Received: [%s]" % ", ".join(map(str, _in.value)))
20-
if _in.value != [x * self.scale for x in [0, 1, 2]]:
18+
reaction(inp) {=
19+
print("Received: [%s]" % ", ".join(map(str, inp.value)))
20+
if inp.value != [x * self.scale for x in [0, 1, 2]]:
2121
sys.stderr.write("ERROR: Value received by Print does not match expectation!\n")
2222
exit(1)
2323
=}
@@ -26,5 +26,5 @@ reactor Print(scale=1) {
2626
main reactor ArrayPrint {
2727
s = new Source()
2828
p = new Print()
29-
s.out -> p._in
29+
s.out -> p.inp
3030
}

test/Python/src/ArrayScale.lf

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ target Python
66
import Print, Source from "ArrayPrint.lf"
77

88
reactor Scale(scale=2) {
9-
mutable input _in
9+
mutable input inp
1010
output out
1111

12-
reaction(_in) -> out {=
13-
for i in range(len(_in.value)):
14-
_in.value[i] *= self.scale
15-
out.set(_in.value)
12+
reaction(inp) -> out {=
13+
for i in range(len(inp.value)):
14+
inp.value[i] *= self.scale
15+
out.set(inp.value)
1616
=}
1717
}
1818

1919
main reactor ArrayScale {
2020
s = new Source()
2121
c = new Scale()
2222
p = new Print(scale=2)
23-
s.out -> c._in
24-
c.out -> p._in
23+
s.out -> c.inp
24+
c.out -> p.inp
2525
}

test/Python/src/ArraySet.lf

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
target Python
2+
3+
reactor Source {
4+
output out
5+
6+
reaction(startup) -> out {=
7+
array = [0, 1, 2]
8+
out.set(array)
9+
=}
10+
}
11+
12+
reactor Print {
13+
input inp
14+
15+
reaction(inp) {=
16+
print("Received: [", end="")
17+
for i in range(len(inp.value)):
18+
if i > 0: print(", ", end="")
19+
print(inp.value[i], end="")
20+
if inp.value[i] != i:
21+
print(f"Expected {i}.") # lf_print_error
22+
sys.exit(1) # and_exit
23+
print("]")
24+
=}
25+
}
26+
27+
main reactor {
28+
s = new Source()
29+
p = new Print()
30+
s.out -> p.inp
31+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
target Python
2+
3+
main reactor CharLiteralInitializer {
4+
state c = 'x'
5+
6+
reaction(startup) {=
7+
if self.c != 'x':
8+
sys.stderr.write("FAILED: Expected 'x', got {:s}.\n".format(self.c))
9+
exit(1)
10+
=}
11+
}

test/Python/src/CountSelf.lf

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ reactor CountSelf2(delay = 100 msec) {
2020
}
2121

2222
reactor Test {
23-
input _in
23+
input inp
2424
state count = 0
2525

26-
reaction(_in) {=
27-
print("Received: {:d}".format(_in.value))
28-
if _in.value != self.count:
26+
reaction(inp) {=
27+
print("Received: {:d}".format(inp.value))
28+
if inp.value != self.count:
2929
sys.stderr.write("ERROR: Expected {:d}.\n".format(self.count))
3030
exit(1)
3131

@@ -36,5 +36,5 @@ reactor Test {
3636
main reactor {
3737
d = new CountSelf2()
3838
t = new Test()
39-
d.out -> t._in
39+
d.out -> t.inp
4040
}

test/Python/src/DanglingOutput.lf

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ reactor Source {
1212
}
1313

1414
reactor Gain {
15-
input _in
15+
input inp
1616
output out
1717

18-
reaction(_in) -> out {=
19-
print("Received ", _in.value)
20-
out.set(_in.value * 2)
18+
reaction(inp) -> out {=
19+
print("Received ", inp.value)
20+
out.set(inp.value * 2)
2121
=}
2222
}
2323

2424
main reactor DanglingOutput {
2525
source = new Source()
2626
container = new Gain()
27-
source.out -> container._in
27+
source.out -> container.inp
2828
}

0 commit comments

Comments
 (0)