Skip to content

Commit

Permalink
Add Rosetta Code Generator/Exponential test
Browse files Browse the repository at this point in the history
Also ensure all RC tests are described consistently, with a forward
slash (the way they are named on the site) rather than a hyphen (the
way they have to be named as files).
  • Loading branch information
rrthomas committed Jul 21, 2024
1 parent 3cdf7e7 commit 5cceea9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions rosettacode/Generator-Exponential.result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
null
37 changes: 37 additions & 0 deletions rosettacode/Generator-Exponential.ursa
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
let count = gen() {
let n = 0
loop {
yield n
n := n + 1
}
}

let powers = gen(m) {
for n of count() {
yield n ** m
}
}

let filtered = gen(s1, s2) {
let v = s1()
let f = s2()
loop {
if v > f {
f := s2()
continue
} else if v < f {
yield v
}
v := s1()
}
}


let squares = powers(2)
let cubes = powers(3)
let f = filtered(squares, cubes)

// Drop first 20 items.
for i of range(20) {f()}
// Print next 10 items.
for i of range(10) {print(f())}
15 changes: 13 additions & 2 deletions src/ursa/examples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,21 @@ Fizz
98
Fizz
Buzz`)
ursaTest('Hello world-Text', 'rosettacode/Hello world-Text', [], 'hello woods!')
ursaTest('Generator/Exponential', 'rosettacode/Generator-Exponential', [], `\
529
576
625
676
784
841
900
961
1024
1089`)
ursaTest('Hello world/Text', 'rosettacode/Hello world-Text', [], 'hello woods!')
// Not run, as this program does not terminate
// ursaTest('Integer sequence', 'rosettacode/Integer sequence')
ursaTest('Loops-Continue', 'rosettacode/Loops-Continue', [], `\
ursaTest('Loops/Continue', 'rosettacode/Loops-Continue', [], `\
1, 2, 3, 4, 5
6, 7, 8, 9, 10`)

Expand Down

0 comments on commit 5cceea9

Please sign in to comment.