Skip to content

Commit

Permalink
test_funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
zoomlogo committed Mar 1, 2024
1 parent 1aff66c commit b5e45a0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
8 changes: 8 additions & 0 deletions test/test_funcs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os, sys
from mpmath import *

THIS_FOLDER = os.path.dirname(os.path.abspath(__file__)) + "/.."
sys.path.insert(1, THIS_FOLDER)

from flax.funcs import *

27 changes: 13 additions & 14 deletions test/test_monads.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# single byte monads
import os, sys
from mpmath import *

Expand All @@ -8,85 +7,85 @@
from flax.main import flax_run as run


def test_abs(): # A
def test_A():
assert run("A") == 0
assert run("A", -3) == 3
assert run("A", 3) == 3


def test_any(): # Ȧ
def test_Adot(): # Ȧ
assert run("Ȧ") == 0
assert run("Ȧ", [0] * 10) == 0
assert run("Ȧ", [0, 0, 1, 0, 0]) == 1
assert run("Ȧ", [1, 2]) == 1


def test_i2b(): # B
def test_B(): # B
assert run("B") == [0]
assert run("B", 12) == [1, 1, 0, 0]
assert run("B", -6) == [-1, -1, 0]
assert run("B", [5, -3, 10]) == [[1, 0, 1], [-1, -1], [1, 0, 1, 0]]


def test_b2i(): # Ḃ
def test_Bdot(): # Ḃ
assert run("Ḃ") == 0
assert run("Ḃ", [1, 1, 0]) == 6
assert run("Ḃ", [-1, -1, -1]) == -7
assert run("Ḃ", [[1, 0, 1, 1], [1, 0, 1]]) == [11, 5]


def test_complement(): # C
def test_C(): # C
assert run("C") == 1
assert run("C", 1) == 0
assert run("C", 10) == -9
assert run("C", [10, -10, [4]]) == [-9, 11, [-3]]


def test_randomly_choose(): # Ċ
def test_Cdot(): # Ċ
assert run("Ċ", [1, 2, 3]) in [1, 2, 3]


def test_i2d(): # D
def test_D(): # D
assert run("D") == [0]
assert run("D", 2) == [2]
assert run("D", 234) == [2, 3, 4]
assert run("D", -23) == [-2, -3]
assert run("D", [-45, 45]) == [[-4, -5], [4, 5]]


def test_d2i(): # Ḋ
def test_Ddot(): # Ḋ
assert run("Ḋ") == 0
assert run("Ḋ", [1, 2]) == 12
assert run("Ḋ", [-6, -9]) == -69
assert run("Ḋ", [[2, 3, 1], [-5, -3]]) == [231, -53]


def test_alleq(): # E
def test_E(): # E
assert run("E", [1, 2, 3]) == 0
assert run("E", [2, 2, 2]) == 1
assert run("E", [[1, 2], [1, 2]]) == 1


def test_aleq_r(): # Ė
def test_Edot(): # Ė
assert run("Ė", [1, 2, 3]) == []
assert run("Ė", [2, 2, 2]) == 2
assert run("Ė", [[1, 2], [1, 2]]) == [1, 2]


def test_flatten(): # F
def test_F(): # F
assert run("F") == [0]
assert run("F", [1, 2]) == [1, 2]
assert run("F", [[[[1]]]]) == [1]
assert run("F", [1, 2, [3, 4, [5], [[6]]], []]) == [1, 2, 3, 4, 5, 6]


def test_falsey_indicies(): # Ḟ
def test_Fdot(): # Ḟ
assert run("Ḟ") == [0]
assert run("Ḟ", [1, 2]) == []
assert run("Ḟ", [1, 0, 2]) == [1]
assert run("Ḟ", [0, 3, 2, 1, 0, 0]) == [0, 4, 5]


def test_group_indicies(): # G
def test_G(): # G
assert run("G", [0]) == [[0]]
assert run("G", [0, 1, 0, 0, 1]) == [[0, 2, 3], [1, 4]]
2 changes: 0 additions & 2 deletions test/test_syntax.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# test syntax things and chain separators
# and niladic atoms
import os, sys
from mpmath import *

Expand Down

0 comments on commit b5e45a0

Please sign in to comment.