Example #1
0
def shlomif_main(args):

    plan(3)

    rand = constructRandom('24')
    game = Game("freecell", rand, True)
    # TEST
    got_s = game.print_layout()
    ok (got_s == '''4C 2C 9C 8C QS 4S 2H
5H QH 3C AC 3H 4H QD
QC 9S 6H 9H 3S KS 3D
5D 2S JC 5C JH 6D AS
2D KD TH TC TD 8D
7H JS KH TS KC 7C
AH 5S 6S AD 8H JD
7S 6C 7D 4D 8S 9D
''',
    'Deal 24',
);

    rand = constructRandom('ms123456')
    game = Game("freecell", rand, True)
    # TEST
    got_s = game.print_layout()
    ok (got_s == '''QD TC AS KC AH KH 6H
6D TD 8D TH 7C 2H 9C
AC AD 5C 5H 8C 9H 9D
JS 8S 4D 4C 2S 7D 3C
7H 7S 9S 2C JC 5S
5D 3S 3D 3H KD JH
6C QS 4S 2D KS TS
JD QH 6S 4H QC 8H
''',
    'Microsoft Deal 123456',
);

    rand = constructRandom('123456')
    game = Game("freecell", rand, True)
    # TEST
    got_s = game.print_layout()
    ok (got_s == '''3D 6C AS TS QC 8D 4D
2D TC 4H JD TD 2H 5C
2C 8S AH KD KH 5S 7C
9C 8C QH 3C 5D 9S QD
AC 9D 7H 6D KS JH
6H TH 8H QS 7D JC
4C 2S 3S 6S 5H 3H
KC JS 9H 4S 7S AD
''',
    'PySolFC deal No. 123456',
);
def shlomif_main(args):

    plan(4)

    card1 = AbstractCard(1001, 0, 1, 2, 3001)
    # TEST
    ok(card1.color == 0, 'card1.color is sane.')

    # TEST
    ok(card1.rank == 2, 'card1.rank')

    card2 = AbstractCard(1001, 0, 3, 7, 3001)
    # TEST
    ok(card2.color == 1, 'card2.color is sane.')

    # TEST
    ok(card2.rank == 7, 'card2.rank')
Example #3
0
#!/usr/bin/python

import sys
from TAP.Simple import diag, is_ok, ok, plan
from euler555 import M_func, S_func

if sys.version_info > (3,):
    long = int
    xrange = range

plan(6)


def eq_ok(have, want, blurb):
    ret = ok(have == want, blurb)
    if (not ret):
        diag("(have = '%s', want = '%s')" % (have, want))
    return ret


def main():
    M_91 = M_func(100, 11, 10)

    # TEST
    is_ok(M_91.calc(101), 91, "M[91](101) == 91")

    # TEST
    is_ok(M_91.calc(91), 91, "M[91](91) == 91")

    # TEST
    ok(M_91.calc_F() == [91], "calc_F")
Example #4
0
def main():
    plan(6)

    # TEST
    mytest(
        """Foundations:
Freecells:
4C 5H QC 5D 2D 7H AH 7S
2C QH 9S 2S KD JS 5S 6C
9C 3C 6H JC TH KH 6S 7D
8C AC 9H 5C TC TS AD 4D
QS 3H 3S JH TD KC 8H 8S
4S 4H KS 6D 8D 7C JD 9D
2H QD 3D AS
""",
        """Foundations:
Freecells:
: 4C 2C 9C 8C QS 4S 2H
: 5H QH 3C AC 3H 4H QD
: QC 9S 6H 9H 3S KS 3D
: 5D 2S JC 5C JH 6D AS
: 2D KD TH TC TD 8D
: 7H JS KH TS KC 7C
: AH 5S 6S AD 8H JD
: 7S 6C 7D 4D 8S 9D
""",
        "Freecell MS deal 24 initial",
    )

    # TEST
    mytest(
        """Foundations:
Freecells:
4C 5H QC 5D 2D 7H AH 7S
2H QH 9S 2S KD JS 5S 6C
9C 3C 6H JC TH KH 6S 7D
8C AC 9H 5C TC TS AD 4D
QS 3H 3S JH TD KC 8H 8S
4S 4H KS 6D 8D 7C JD 9D
   QD 3D AS
      2C
""",
        """Foundations:
Freecells:
: 4C 2H 9C 8C QS 4S
: 5H QH 3C AC 3H 4H QD
: QC 9S 6H 9H 3S KS 3D 2C
: 5D 2S JC 5C JH 6D AS
: 2D KD TH TC TD 8D
: 7H JS KH TS KC 7C
: AH 5S 6S AD 8H JD
: 7S 6C 7D 4D 8S 9D
""",
        "With longer column."
    )

    # TEST
    mytest(
        """Foundations:
Freecells:
4C 5H QC 5D 2D 7H AH 7S
2H QH 9S 2S KD JS 5S 6C
9C 3C 6H JC TH KH 6S 7D
8C AC 9H 5C TC TS AD 4D
QS 3H 3S JH TD    8H 8S
   4H KS 6D 8D    JD
   QD 3D AS       KC
      2C          9D
      4S
      7C
""",
        """Foundations:
Freecells:
: 4C 2H 9C 8C QS
: 5H QH 3C AC 3H 4H QD
: QC 9S 6H 9H 3S KS 3D 2C 4S 7C
: 5D 2S JC 5C JH 6D AS
: 2D KD TH TC TD 8D
: 7H JS KH TS
: AH 5S 6S AD 8H JD KC 9D
: 7S 6C 7D 4D 8S
""",
        "With two longer columns."
    )

    # TEST
    mytest(
        """Freecells:
4C 5H QC 5D 2D 7H AH 7S
2H QH 9S 2S KD JS 5S 6C
9C 3C 6H JC TH KH 6S 7D
8C AC 9H 5C TC TS AD 4D
QS 3H 3S JH TD    8H 8S
   4H KS 6D 8D    JD
   QD 3D AS       KC
      2C          9D
      4S
      7C
""",
        """Freecells:
: 4C 2H 9C 8C QS
: 5H QH 3C AC 3H 4H QD
: QC 9S 6H 9H 3S KS 3D 2C 4S 7C
: 5D 2S JC 5C JH 6D AS
: 2D KD TH TC TD 8D
: 7H JS KH TS
: AH 5S 6S AD 8H JD KC 9D
: 7S 6C 7D 4D 8S
""",
        "Without a foundations line"
    )

    # TEST
    mytest(
        """Foundations:
4C 5H QC 5D 2D 7H AH 7S
2H QH 9S 2S KD JS 5S 6C
9C 3C 6H JC TH KH 6S 7D
8C AC 9H 5C TC TS AD 4D
QS 3H 3S JH TD    8H 8S
   4H KS 6D 8D    JD
   QD 3D AS       KC
      2C          9D
      4S
      7C
""",
        """Foundations:
: 4C 2H 9C 8C QS
: 5H QH 3C AC 3H 4H QD
: QC 9S 6H 9H 3S KS 3D 2C 4S 7C
: 5D 2S JC 5C JH 6D AS
: 2D KD TH TC TD 8D
: 7H JS KH TS
: AH 5S 6S AD 8H JD KC 9D
: 7S 6C 7D 4D 8S
""",
        "Without a Freecells line"
    )

    # TEST
    mytest(
        """4C 5H QC 5D 2D 7H AH 7S
2H QH 9S 2S KD JS 5S 6C
9C 3C 6H JC TH KH 6S 7D
8C AC 9H 5C TC TS AD 4D
QS 3H 3S JH TD    8H 8S
   4H KS 6D 8D    JD
   QD 3D AS       KC
      2C          9D
      4S
      7C
""",
        """: 4C 2H 9C 8C QS
: 5H QH 3C AC 3H 4H QD
: QC 9S 6H 9H 3S KS 3D 2C 4S 7C
: 5D 2S JC 5C JH 6D AS
: 2D KD TH TC TD 8D
: 7H JS KH TS
: AH 5S 6S AD 8H JD KC 9D
: 7S 6C 7D 4D 8S
""",
        "With neither a Freecells line nor a Foundations line."
    )
Example #5
0
def shlomif_main(args):

    plan(8)

    rand = constructRandom('24')
    game = Game("freecell", rand, True)
    # TEST
    got_s = game.print_layout()
    ok (got_s == '''4C 2C 9C 8C QS 4S 2H
5H QH 3C AC 3H 4H QD
QC 9S 6H 9H 3S KS 3D
5D 2S JC 5C JH 6D AS
2D KD TH TC TD 8D
7H JS KH TS KC 7C
AH 5S 6S AD 8H JD
7S 6C 7D 4D 8S 9D
''',
    'Deal 24',
);

    rand = constructRandom('ms123456')
    game = Game("freecell", rand, True)
    # TEST
    got_s = game.print_layout()
    ok (got_s == '''QD TC AS KC AH KH 6H
6D TD 8D TH 7C 2H 9C
AC AD 5C 5H 8C 9H 9D
JS 8S 4D 4C 2S 7D 3C
7H 7S 9S 2C JC 5S
5D 3S 3D 3H KD JH
6C QS 4S 2D KS TS
JD QH 6S 4H QC 8H
''',
    'Microsoft Deal 123456',
);

    rand = constructRandom('123456')
    game = Game("freecell", rand, True)
    # TEST
    got_s = game.print_layout()
    ok (got_s == '''3D 6C AS TS QC 8D 4D
2D TC 4H JD TD 2H 5C
2C 8S AH KD KH 5S 7C
9C 8C QH 3C 5D 9S QD
AC 9D 7H 6D KS JH
6H TH 8H QS 7D JC
4C 2S 3S 6S 5H 3H
KC JS 9H 4S 7S AD
''',
    'PySolFC deal No. 123456',
);

    rand = constructRandom('ms3000000000')
    game = Game("freecell", rand, True)
    # TEST
    got_s = game.print_layout()
    ok (got_s == '''8D TS JS TD JH JD JC
4D QS TH AD 4S TC 3C
9H KH QH 4C 5C KD AS
9D 5D 8S 4H KS 6S 9S
6H 2S 7H 3D KC 2C
9C 7C QC 7S QD 7D
6C 3H 8H AC 6D 3S
8C AH 2H 5H 2D 5S
''',
    'Microsoft Deal #3E9 - long seed.',
);

    rand = constructRandom('ms6000000000')
    game = Game("freecell", rand, True)
    # TEST
    got_s = game.print_layout()
    ok (got_s == '''2D 2C QS 8D KD 8C 4C
3D AH 2H 4H TS 6H QD
4D JS AD 6S JH JC JD
KH 3H KS AS TC 5D AC
TD 7C 9C 7H 3C 3S
QH 9H 9D 5S 7S 6C
5C 5H 2S KC 9S 4S
6D QC 8S TH 7D 8H
''',
    'Microsoft Deal #6E9 - extra long seed.',
);

    inp = 'ms12345678'
    got = random__long2str(random__str2long(inp))

    # TEST
    ok (got == inp, 'long2str ms roundtrip.')

    inp = '246007891097'
    got = random__long2str(random__str2long(inp))

    # TEST
    ok (got == inp, 'long2str PySolFC roundtrip.')

    proto_inp = '246007891097'
    inp = random__str2long(proto_inp)
    got = random__str2long(random__long2str(inp))

    # TEST
    ok (got == inp, 'str2long PySolFC roundtrip.')
Example #6
0
#!/usr/bin/env python
from TAP.Simple import diag, ok, plan

from euler_423_v2 import pascal_sum


def check_sum(n, p, val):
    ret = pascal_sum(n, p)
    if not ok(ret == val, "pascal_sum(%d,%d)" % (n, p)):
        diag("got = %d ; expected = %d" % (ret, val))


plan(7)

# TEST
check_sum(2, 0, 30)

# TEST
check_sum(2, 1, 6 * 5 + 6 * 1)

# TEST
check_sum(3, 0, 6 * 5 * 5)

# TEST
check_sum(3, 1, 6 * 5 * 5 + 6 * 1 * 5 + 6 * 5 * 1)

# TEST
check_sum(3, 2, 6 * 6 * 6)

# TEST
check_sum(4, 0, 6 * 5 * 5 * 5)
Example #7
0
#!/usr/bin/env python
from TAP.Simple import diag, ok, plan

from euler_423_v2 import pascal_sum


def check_sum(n, p, val):
    ret = pascal_sum(n, p)
    if not ok(ret == val, "pascal_sum(%d,%d)" % (n, p)):
        diag("got = %d ; expected = %d" % (ret, val))

plan(7)

# TEST
check_sum(2, 0, 30)

# TEST
check_sum(2, 1, 6*5+6*1)

# TEST
check_sum(3, 0, 6*5*5)

# TEST
check_sum(3, 1, 6*5*5+6*1*5+6*5*1)

# TEST
check_sum(3, 2, 6*6*6)

# TEST
check_sum(4, 0, 6*5*5*5)
Example #8
0
def shlomif_main(args):

    plan(8)

    rand = constructRandom('24')
    game = Game("freecell", rand, True)
    # TEST
    got_s = game.print_layout()
    ok(
        got_s == '''4C 2C 9C 8C QS 4S 2H
5H QH 3C AC 3H 4H QD
QC 9S 6H 9H 3S KS 3D
5D 2S JC 5C JH 6D AS
2D KD TH TC TD 8D
7H JS KH TS KC 7C
AH 5S 6S AD 8H JD
7S 6C 7D 4D 8S 9D
''',
        'Deal 24',
    )

    rand = constructRandom('ms123456')
    game = Game("freecell", rand, True)
    # TEST
    got_s = game.print_layout()
    ok(
        got_s == '''QD TC AS KC AH KH 6H
6D TD 8D TH 7C 2H 9C
AC AD 5C 5H 8C 9H 9D
JS 8S 4D 4C 2S 7D 3C
7H 7S 9S 2C JC 5S
5D 3S 3D 3H KD JH
6C QS 4S 2D KS TS
JD QH 6S 4H QC 8H
''',
        'Microsoft Deal 123456',
    )

    rand = constructRandom('123456')
    game = Game("freecell", rand, True)
    # TEST
    got_s = game.print_layout()
    ok(
        got_s == '''3D 6C AS TS QC 8D 4D
2D TC 4H JD TD 2H 5C
2C 8S AH KD KH 5S 7C
9C 8C QH 3C 5D 9S QD
AC 9D 7H 6D KS JH
6H TH 8H QS 7D JC
4C 2S 3S 6S 5H 3H
KC JS 9H 4S 7S AD
''',
        'PySolFC deal No. 123456',
    )

    rand = constructRandom('ms3000000000')
    game = Game("freecell", rand, True)
    # TEST
    got_s = game.print_layout()
    ok(
        got_s == '''8D TS JS TD JH JD JC
4D QS TH AD 4S TC 3C
9H KH QH 4C 5C KD AS
9D 5D 8S 4H KS 6S 9S
6H 2S 7H 3D KC 2C
9C 7C QC 7S QD 7D
6C 3H 8H AC 6D 3S
8C AH 2H 5H 2D 5S
''',
        'Microsoft Deal #3E9 - long seed.',
    )

    rand = constructRandom('ms6000000000')
    game = Game("freecell", rand, True)
    # TEST
    got_s = game.print_layout()
    ok(
        got_s == '''2D 2C QS 8D KD 8C 4C
3D AH 2H 4H TS 6H QD
4D JS AD 6S JH JC JD
KH 3H KS AS TC 5D AC
TD 7C 9C 7H 3C 3S
QH 9H 9D 5S 7S 6C
5C 5H 2S KC 9S 4S
6D QC 8S TH 7D 8H
''',
        'Microsoft Deal #6E9 - extra long seed.',
    )

    inp = 'ms12345678'
    got = random__long2str(random__str2long(inp))

    # TEST
    ok(got == inp, 'long2str ms roundtrip.')

    inp = '246007891097'
    got = random__long2str(random__str2long(inp))

    # TEST
    ok(got == inp, 'long2str PySolFC roundtrip.')

    proto_inp = '246007891097'
    inp = random__str2long(proto_inp)
    got = random__str2long(random__long2str(inp))

    # TEST
    ok(got == inp, 'str2long PySolFC roundtrip.')
Example #9
0
File: rx-test.py Project: pcurry/rx
import collections
import json
import re

import Rx

from TAP.Simple import isa_ok
from TAP.Simple import ok
from TAP.Simple import plan

plan(None)

rx = Rx.Factory({"register_core_types": True})

isa_ok(rx, Rx.Factory)

index = json.loads(file('spec/index.json').read())

test_data = {}
test_schemata = {}


def normalize(entries, test_data):
    if entries == '*':
        entries = {"*": None}

    if isinstance(entries, collections.Sequence):
        new_entries = {}
        for n in entries:
            new_entries[n] = None
Example #10
0
#!/usr/bin/env python3

from TAP.Simple import plan
# TEST:source "$^CURRENT_DIRNAME/../lib/FC_Solve/__init__.py"
from FC_Solve import FC_Solve

plan(79)


def test_null_plan():
    fcs = FC_Solve()

    name = "null plan"

    # TEST*$compile_flares_plan_ok
    fcs.compile_flares_plan_ok(name, None)

    # TEST
    fcs.flare_plan_num_items_is(name, 2)

    # TEST*$flare_plan_item_is_run_indef
    fcs.flare_plan_item_is_run_indef(name, 0, 0)

    # TEST*$flare_plan_item_is_checkpoint
    fcs.flare_plan_item_is_checkpoint(name + " No. 1", 1)


def test_empty_plan():
    fcs = FC_Solve()

    name = "empty string plan"
Example #11
0
#!/usr/bin/env python3

from TAP.Simple import plan
# TEST:source "$^CURRENT_DIRNAME/../lib/FC_Solve/__init__.py"
from FC_Solve import FC_Solve

plan(24)


def main():
    fcs = FC_Solve()

    # TEST*$test_befs
    fcs.test_befs_weights(
        "Simple - all integers",
        "5,4,3,0,2",
        [5.0, 4.0, 3.0, 0.0, 2.0])

    # TEST*$test_befs
    fcs.test_befs_weights(
        "Simple - fractions",
        "0.2,0.3,0.4,0.5,0.6",
        [0.2, 0.3, 0.4, 0.5, 0.6])

    # TEST*$test_befs
    fcs.test_befs_weights(
        "Testing end after three numbers",
        "0.2,0.35,0.4\x00500\x00600.7\x00",
        [0.2, 0.35, 0.4, 0, 0])

    # TEST*$test_befs
Example #12
0
#!/usr/bin/python

import sys
from TAP.Simple import diag, is_ok, ok, plan
from euler555 import M_func, S_func

if sys.version_info > (3, ):
    long = int

plan(6)


def eq_ok(have, want, blurb):
    ret = ok(have == want, blurb)
    if (not ret):
        diag("(have = '%s', want = '%s')" % (have, want))
    return ret


def main():
    M_91 = M_func(100, 11, 10)

    # TEST
    is_ok(M_91.calc(101), 91, "M[91](101) == 91")

    # TEST
    is_ok(M_91.calc(91), 91, "M[91](91) == 91")

    # TEST
    ok(M_91.calc_F() == [91], "calc_F")
Example #13
0
def main():
    plan(6)

    # TEST
    test_board(
        24,
        """4C 2C 9C 8C QS 4S 2H
5H QH 3C AC 3H 4H QD
QC 9S 6H 9H 3S KS 3D
5D 2S JC 5C JH 6D AS
2D KD TH TC TD 8D
7H JS KH TS KC 7C
AH 5S 6S AD 8H JD
7S 6C 7D 4D 8S 9D
"""
    )

    # TEST
    test_board(
        11982,
        """AH 3D KD JC 6C JD KC
AS 3H 6H 5D 2C 7D 8D
4H QS 5S 5C TH 8H 2S
AC QC 4D 8C QH 9C 3S
2D 8S 9H 9D 6D 2H
6S 7H JH TD TC QD
TS AD 9S KH 4S 4C
JS KS 3C 7C 7S 5H
"""
    )

    # TEST
    test_board(
        1234567,
        """2H 7S 4S 4D 8C KD QD
9C KH 5D 6C TC 5H 7D
JC TH JD 2S KS TS 9H
4H 8H 5C 9D 5S JS 3D
AD 3H 6D JH 3S KC
QC 9S 8D AS 7C 8S
AC 3C QH TD 6S 6H
2C 2D 4C 7H AH QS
"""
    )

    # TEST
    test_board_l(
        24,
        """4C 2C 9C 8C QS 4S 2H
5H QH 3C AC 3H 4H QD
QC 9S 6H 9H 3S KS 3D
5D 2S JC 5C JH 6D AS
2D KD TH TC TD 8D
7H JS KH TS KC 7C
AH 5S 6S AD 8H JD
7S 6C 7D 4D 8S 9D
"""
    )

    # TEST
    test_board_l(
        3000000000,
        """8D TS JS TD JH JD JC
4D QS TH AD 4S TC 3C
9H KH QH 4C 5C KD AS
9D 5D 8S 4H KS 6S 9S
6H 2S 7H 3D KC 2C
9C 7C QC 7S QD 7D
6C 3H 8H AC 6D 3S
8C AH 2H 5H 2D 5S
"""
    )

    # TEST
    test_board_l(
        6000000000,
        """2D 2C QS 8D KD 8C 4C
3D AH 2H 4H TS 6H QD
4D JS AD 6S JH JC JD
KH 3H KS AS TC 5D AC
TD 7C 9C 7H 3C 3S
QH 9H 9D 5S 7S 6C
5C 5H 2S KC 9S 4S
6D QC 8S TH 7D 8H
"""
    )
Example #14
0
#!/usr/bin/env python3

from TAP.Simple import ok, plan
# TEST:source "$^CURRENT_DIRNAME/../lib/FC_Solve/__init__.py"
from FC_Solve import FC_Solve
import re
import os

plan(14)


def test_resume_solution():
    testname = "With RunIndef - "

    fcs = FC_Solve()

    limit = 10
    fcs.limit_iterations(limit)

    ret = fcs.solve_board(
            """4C 2C 9C 8C QS 4S 2H
5H QH 3C AC 3H 4H QD
QC 9S 6H 9H 3S KS 3D
5D 2S JC 5C JH 6D AS
2D KD TH TC TD 8D
7H JS KH TS KC 7C
AH 5S 6S AD 8H JD
7S 6C 7D 4D 8S 9D
"""
    )