-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
242 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
src/commonTest/kotlin/rules/nontotalistic/GenerationsINTTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package rules.nontotalistic | ||
|
||
import PLATFORM | ||
import readResource | ||
import rules.RuleFamily | ||
import rules.enumerateRules | ||
import rules.nontotalistic.rules.INT | ||
import rules.nontotalistic.rules.INTGenerations | ||
import rules.randomRules | ||
import simulation.SparseGrid | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class GenerationsINTTest { | ||
@Test | ||
fun canonise_rulestring_correctly() { | ||
// Loading test cases | ||
val testCases = readResource("rules/nontotalistic/generationsIntParsingTest.txt").split("\n").map { it.trim() } | ||
|
||
var rulestring = "" | ||
var canonRulestring = "" | ||
for (line in testCases) { | ||
when { | ||
// Loading rulestring | ||
line.startsWith("#R") -> rulestring = line.replace("#R ", "") | ||
|
||
// Loading canon rulestring | ||
line.startsWith("#C") -> canonRulestring = line.replace("#C ", "") | ||
|
||
// Running the test case | ||
!line.startsWith("#") -> { | ||
try { | ||
println(rulestring) | ||
val rule = INTGenerations(rulestring) | ||
assertEquals(canonRulestring, rule.rulestring) | ||
} catch (ignored: IllegalArgumentException) {} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun simulate_rule_correctly() { | ||
// Loading test cases | ||
val testCases = readResource("rules/nontotalistic/generationsIntSimulationTest.txt").split("\n").map { it.trim() } | ||
|
||
var rulestring = "" | ||
var generations = 0 | ||
var initial = "" | ||
var final = "" | ||
for (line in testCases) { | ||
when { | ||
// Loading rulestring | ||
line.startsWith("#R") -> rulestring = line.replace("#R ", "") | ||
|
||
// Loading generations to run | ||
line.startsWith("#G") -> generations = line.replace("#G ", "").toInt() | ||
|
||
// Loading initial and final to patterns | ||
line.startsWith("#I") -> initial = line.replace("#I ", "") | ||
line.startsWith("#O") -> final = line.replace("#O ", "") | ||
|
||
// Running the test case | ||
!line.startsWith("#") -> { | ||
try { | ||
val grid = SparseGrid(initial, INTGenerations(rulestring)) | ||
grid.step(generations) | ||
assertEquals(final, grid.toRLE()) | ||
} catch (ignored: IllegalArgumentException) {} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun calculate_rule_range_correctly() { | ||
// Loading test cases | ||
val testCases = readResource("rules/nontotalistic/intRuleRangeTest.txt").split("\n").map { it.trim() } | ||
|
||
var rulestring = "" | ||
var rle = "" | ||
var type = "" | ||
var minRule = "" | ||
var maxRule = "" | ||
|
||
for (line in testCases) { | ||
when { | ||
// Loading rulestring | ||
line.startsWith("#R") -> rulestring = line.replace("#R ", "") | ||
|
||
// Loading RLE | ||
line.startsWith("#I") -> rle = line.replace("#I ", "") | ||
|
||
// Loading pattern type | ||
line.startsWith("#T") -> type = line.replace("#T ", "") | ||
|
||
// Loading rule range | ||
line.startsWith("#MIN") -> minRule = line.replace("#MIN ", "") | ||
line.startsWith("#MAX") -> maxRule = line.replace("#MAX ", "") | ||
|
||
// Running the test case | ||
!line.startsWith("#") -> { | ||
try { | ||
val grid = SparseGrid(rle, INTGenerations(rulestring)) | ||
val pattern = grid.identify() | ||
|
||
assertEquals(type, pattern.toString()) | ||
assertEquals(minRule, (pattern!!.ruleRange!!.first as RuleFamily).rulestring) | ||
assertEquals(maxRule, (pattern.ruleRange!!.second as RuleFamily).rulestring) | ||
} catch (ignored: IllegalArgumentException) {} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun enumerate_all_rules() { | ||
if (PLATFORM != "JS") | ||
assertEquals(16384, enumerateRules(INTGenerations("B3/S23"), INTGenerations("B2n3/S234")).count()) | ||
} | ||
|
||
@Test | ||
fun check_deterministic() { | ||
assertEquals( | ||
randomRules(INTGenerations("B2n3/S23-q"), INTGenerations("B2aen34-q/S2367e8"), 10).take(100).map { it.toString() }.toList(), | ||
randomRules(INTGenerations("B2n3/S23-q"), INTGenerations("B2aen34-q/S2367e8"), 10).take(100).map { it.toString() }.toList() | ||
) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/commonTest/resources/rules/nontotalistic/generationsIntParsingTest.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#R g5b2n3s23-q | ||
#C 23-q/2n3/5 | ||
|
||
#R G3/B3/S23 | ||
#C 23/3/3 | ||
|
||
#R B3/S01234a4-a5678/C56/NC2 | ||
#C 012345678/3/56/C2 | ||
|
||
#R 3/01234a4-a5678/3/K | ||
#C 3/012345678/3/K | ||
|
||
#R g5b2ca3e3cs106-aK | ||
#C 016-a/2ac3ce/5/K | ||
|
||
#R g10b24m3o3mps106h | ||
#C 016/234m/10H | ||
|
||
#R C3B2c2k2a3k3a3j4k4a4y4w5kS02c2e2k2n3a3n4w5k5aFE | ||
#C 02-ai3an4w5ak/2ack3ajk4akwy5k/3/FE | ||
|
||
#R g3/B2a3q3j3r4w4z/S1c2e2k2i3q3j3r4w/NFC | ||
#C 1c2eik3jqr4w/2a3jqr4wz/3/FC | ||
|
||
#R B3cea5/S223eiac/C7 | ||
#C 23acei/3ace5/7 | ||
|
||
#R B2ek2i3re4r/S1c1e2e2a3r4a/C45/NFC | ||
#C 12ae3r4a/2eik3er4r/45/FC | ||
|
||
#R B0xdxf/S2x1ea/G10/NV2 | ||
#C 1ea2x/0xc/10/V2 |
29 changes: 29 additions & 0 deletions
29
src/commonTest/resources/rules/nontotalistic/generationsIntRuleRangeTest.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#R 23/3/3 | ||
#I 7.2A2.$5.A2BAB.$4.2A2B2.A$3.AB.2A.2A$2.AB2A2.3A$.2A.A.A2.A.$.2BA.A2B2A.$A2BA2.B2.2A$2A2.A.A2.B.$.B.5AB.A$2.3A2.A.A! | ||
#MIN 2-n3-e/3-ce/3 | ||
#MAX 0234cikw5-acr678/2i34cty5eq678/3 | ||
#T (-1, 1)c/4 Spaceship | ||
|
||
#R 23/3/3 | ||
#I 2.3A.$.A.2A.$2A3.A$.A.2A.$2.3A! | ||
#MIN 23-cy/3-ck/3 | ||
#MAX 234cktwyz5-iq678/34-acijrt5-enqy6-i78/3 | ||
#T (-4, 0)c/14 Spaceship | ||
|
||
#R 01234/0134/3 | ||
#I A.A3.$6.$6.$A.A3.$2.2A.A$2.3A.$.3A2.$2.A3.$5.A! | ||
#MIN 012-cn3i4eiknrt/013ainr4anrt/3 | ||
#MAX 012345ekny/012k345-aen6cen/3 | ||
#T (0, 1)c/6 Spaceship | ||
|
||
#R 01234/0134/3 | ||
#I A.A3.$6.$6.$A.A3.$2.2A.A$2.3A.$.3A2.$2.A3.$5.A! | ||
#MIN 012-cn3i4eiknrt/013ainr4anrt/3 | ||
#MAX 012345ekny/012k345-aen6cen/3 | ||
#T (0, 1)c/6 Spaceship | ||
|
||
#R 1c23/3/10 | ||
#I .AH$A2I$A2I$.AH! | ||
#MIN 1c2ak/3aij/10 | ||
#MAX 01c234-ar5678/2-ae345678/10 | ||
#T P60 Oscillator |
39 changes: 39 additions & 0 deletions
39
src/commonTest/resources/rules/nontotalistic/generationsIntSimulationTest.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#R 3a/1e/3 | ||
#G 10 | ||
#I 3A$.2A! | ||
#O 9.A2.A$8.AB2.B$10.2B.B$14.B$9.A2.A2.B$8.AB2.B3.B$10.B2.B3.B$14.B3.B$.A8.B4.BA2.BA$AB7.B.B3.A3.A$.A6.B3.B2.A3.A$6.AB5.B.BA2.BA$7.A.A4.B3.B$8.AB3.B3.B$9.A.AB3.B$10.A.A2.B$10.B3.B$8.AB.B.B$9.A2.B$12.A! | ||
|
||
#R 012-ei345ny/012ckn3457c8/3 | ||
#G 240 | ||
#I 2A2.2A2.2A2.2A2.2A2.2A11.$24.2A7.$33.$24.A8.$10.A5.A11.2A3.$10.A.A4.4A.A4.A5.$9.A.3A3.4A6.A5.$12.2A2.A15.A$13.A12.A2.4A$17.A5.A6.2A.$17.A5.2A8.$8.A15.AB7.$8.A.2A13.2A6.$5.A2.3A.A13.2A5.$6.4A23.$5.A.3A2.A5.2A2.2A9.$8.A4.A! | ||
#O 2A2.2A2.2A2.2A2.2A2.2A2.2A2.2A2.2A2.2A2.2A2.2A2.2A2.2A2.2A2.2A2.2A2.2A2.2A2.2A2.2A2.2A2.2A2.2A2.2A2.2A$104.2A2$104.A$108.2A$95.A4.A.A4.A$83.A11.A4.A6.A$82.A.A27.A$94.A2.A8.A2.4A$93.A2.A6.A6.2A$92.A10.2A$92.2A10.AB$92.2A11.2A$106.2A2$90.2A2.2A2.2A2.2A! | ||
|
||
#R 1e2-a3-cij4aijkrtz5cnqr/2ce3aejnr4aj5y6a/3 | ||
#G 130 | ||
#I 36.AB$35.3AB$35.A2.A$32.AB.A2.A$29.5A.A2.A$29.A2.A.BA2.A$29.A2.A.AB3A$15.AB5.AB5.A2.A$30A2.A$A$39A$14.AB11.AB7.ABA$38.A$38.A$.A5.BA13.BA4.BA4.BA2.A$B.37A$.A$.A$.38A$2.AB28.AB4.A$37.2A$37.BA$2.BA22.BA4.BA4.A$.38A! | ||
#O 2A39.3ABA$41.A2.AB$35.AB4.A2.A$35.B3A2.A2.A$35.A2.A2.A2.A$20.8A7.A2.A2.B3A$27.B2A.AB2.A2.A3.BA$22.14A2.A2$20.25A$30.AB12.A$44.A$44.A$44.A$7.38A$7.A$7.A$7.38A$44.A$44.A$44.A$44.A$7.38A! | ||
|
||
#R 012345-r/45-r6ak7e8/3 | ||
#G 100 | ||
#I 10A$A2.AB4.A$A.6A.A$A.A.AB.A.A$A.A.2A.A.A$A.A.2A.A.A$A.A4.A.A$A.6A.A$A8.A$10A! | ||
#O 10A$A8.A$A.6A.A$A.A4.A.A$A.A.2A.A.A$A.AB2A.A.A$A.2A3.A.A$A.6A.A$A6.B2A$10A! | ||
|
||
#R 13-m/23m4/4H | ||
#G 30 | ||
#I A3.A.3A2.A.3A$5A.2A2.A.3A$14.2A$2.A2.5A.3A$A.A.A2.A.3A$4.4A.2A.A2.A$.A10.3A$2.A2.A2.2A2.4A$A2.3A.3A2.3A$.A7.2A! | ||
#O 2.2A$2.ABA$2.4C$.2C3.2C$2C6.2C$BC7.CB14$8.A$8.2B$8.AB$13.BA$13.2B$14.A8$4.A$3.2A$5.A! | ||
|
||
#R 12aek/2cek/9 | ||
#G 40 | ||
#I .A3.3A.A$2A.A.3A$3A.3A2.A$A2.A.A.2A$3.3A.3A$A2.A2.A.2A$.A2.3A.2A$2A.A.A.2A! | ||
#O 22.C2D$6.2A15.DFABA$20.G.C2.GECA$21.H.EFABA$20.G2H.A18$D.E.D$2E.2E$EGAGE$.BHB$ACFCA$.ADA$.ABA! | ||
|
||
#R 1ca2x3ac4adjanawa/2aacaeaiakana/3/V2 | ||
#G 100 | ||
#I 3.2A9.$4.2B8.$5.B8.$2.2A2.A7.$3.AB2.A6.$5.A2.2B4.$9.BA3.$10.A3.$.BA11.$A2.B10.$.B2.A5.2A2.$4.B6.2A.$6.BA5.A$8.2AB2.B$8.A2.2A.$6.A7.$6.2A6.$14.$10.A3.$9.2B3.$9.2A! | ||
#O 2A$2B59$3.2A$3.2B59$6.2A$6.2B6$6.B2$8.B3$10.B7.2A$12.BA4.BA$11.ABA6.A$19.B$17.2A$16.BA$15.BA$14.2A$6.2A2.AB2.A$5.2A3.2A.B$4.A7.A$4.B$6.A$6.2A$8.A$8.BA$10.2A3.A$11.A2.2A$14.A$7.B3.AB$11.2A2$10.B! | ||
|
||
#R 1ca2x3ac4adjanawa/0xg2aacaeaiakana/3/V2 | ||
#G 100 | ||
#I 2A3.A2.2A.$A.A3.A.A2.$3.A5.A.$.A.5A.A.$.3A.A.2A.A$4.2A3.2A$2.A6.A.$5A2.A.A.$5.3A2.A$3.4A2.A! | ||
#O 32.2A$32.2B7$27.2A$27.2B$29.A$27.A.B$28.A$28.A$28.2A3$34.A12.2A$24.A3.B.A2.A14.2B14.A$22.AB.B4.A2.A4.B10.A13.B.2A40.BA$21.BA8.2B17.A14.BA40.BA$31.A7.B10.B$23.B5.2A12.A.B4.A23.2A$17.A10.2A13.A4.AB.A22.2B$17.3B2.A20.BA3.AB18.A2.AB$19.B2.BA21.A5.B16.AB2.B3.B22.A2.BA$16.2A2.2B27.2ABA8.A7.AB25.3B3.BA$16.A4.A.A13.BA3.2A.A15.2A7.A2.B21.2A3.BA$28.A.B6.BA3.A19.B3.A6.B.B12.B$20.B20.2A4.BAB13.A2.AB.A2.A$6.AB2.A5.2A9.AB.A11.2AB3.A14.2A2.2B3.A$6.AB3.3B2.ABA8.ABA13.A13.B2.2A2.2A7.2B16.B$8.AB3.2A3.A3.3A11.2B21.A2.2A4.3B2.2A$17.B4.BA.2A9.3B6.B2.A9.A3.2A5.B$16.2A7.BA10.2B8.BA9.A7.A$16.A3.AB24.BA10.2A5.BAB.A$20.2A.AB8.A7.B.B2.A16.BA$22.3A8.AB2.B2A2.A23.A$30.3A3.AB12.2B4.ABA6.AB.A$25.A2.A3.B.A4.BA9.2B4.AB6.A3.A$AB22.B.2B2.BA5.2ABA8.A2.A14.2B$AB24.B23.2B8.B2.2B2.2A3.A$25.A24.2B11.2B6.B2A$74.2A$76.A$67.A$65.2A.A4.A$48.B16.AB2.A2.AB.B.A40.BA$46.A20.B.BA3.A.A41.BA$39.2B6.2B17.B.B6.A.2A$39.2A7.BA22.2B4.A$49.A26.B$72.A.A$70.B3.2A3$77.BA$75.B.2A$76.A58$60.2B$60.2A! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters