Skip to content

Commit

Permalink
Add headers to eyeball check script
Browse files Browse the repository at this point in the history
  • Loading branch information
orome committed Oct 24, 2023
1 parent 027bf70 commit 7c3457b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
pip install -r requirements.txt
# Skip for Windows; path setting there isn't worth the trouble
# TBD - Fix f strings for earlier Python versions
- name: Run eyeball tests
if: runner.os != 'Windows'
run: |
Expand Down
54 changes: 48 additions & 6 deletions tests/eyeball.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,55 @@

from automata import *

def eyeball_basic_ca(rule_number: int, initial_conditions: str, frame_steps: int, frame_width: int) -> None:
test_ca = CellularAutomata(rule_number, initial_conditions, frame_steps=frame_steps, frame_width=frame_width)

print(f"====================\nrule_number: {rule_number}\ninitial_conditions: {initial_conditions}\nframe_steps: {frame_steps}\nframe_width: {frame_width}\n====================")
HEADER_LENGTH = 100
DEFAULT_FRAME_STEPS = 30
DEFAULT_FRAME_WIDTH = 81


def print_header(level, label='', mark=None) -> None:
if mark is None:
mark = {0: '▲▼', 1: '==', 2: '--', 3: '- ', 4: ' . '}[level]
rule = (mark * (HEADER_LENGTH//2))[:((HEADER_LENGTH+1-(len(label)+2))//2)]

header_text = f"{rule} {label} {rule[::-1]}"[:HEADER_LENGTH]
header_start = '\033[1m' if level <= 1 else ''
header_end = '\033[0;0m' if level <= 1 else ''
header_blanks = '\n' if level != 1 else '\n\n'

print(f"{header_blanks}{header_start}{header_text}{header_end}")


def eyeball_basic_ca(rule_number: int, initial_conditions: str, base: int,
frame_steps: int = DEFAULT_FRAME_STEPS, frame_width: int = DEFAULT_FRAME_WIDTH) -> None:
test_ca = CellularAutomata(rule_number, initial_conditions, base,
frame_steps=frame_steps, frame_width=frame_width)

print_header(3, f"{rule_number}+{base} @ {initial_conditions}")
print(f"rule_number: {rule_number}\n"
f"base: {base}\n"
f"initial_conditions: {initial_conditions}\n"
f"frame_steps: {frame_steps}\n"
f"frame_width: {frame_width}\n")
print(test_ca.to_dict()['args'])
print(test_ca)

eyeball_basic_ca(30, '1000000', frame_steps=10, frame_width=31)
eyeball_basic_ca(90, '1', frame_steps=30, frame_width=51)
eyeball_basic_ca(130, '1', frame_steps=5, frame_width=21)

print_header(0, ' Automata Eyeball Checks ')

print_header(1, 'Basics')

print_header(2, 'Basic Lattice')
print(f"frame_steps: {DEFAULT_FRAME_STEPS}\n"
f"frame_width: {DEFAULT_FRAME_WIDTH}\n")

eyeball_basic_ca(30, '1000000', 2)
eyeball_basic_ca(90, '1', 2,)
eyeball_basic_ca(130, '1', 2)
eyeball_basic_ca(130, '101010101', 3)
eyeball_basic_ca(130, '202121212201', 3)
eyeball_basic_ca(1, '202121212201', 3)
eyeball_basic_ca(2398373402626, '1', 3)

print_header(0, ' (End) Automata Eyeball Checks (End) ')
print("\n")

0 comments on commit 7c3457b

Please sign in to comment.