Commit 0b2d2158 authored by Vít Novotný's avatar Vít Novotný
Browse files

added python 3.x tests and better python 3.x support

parent 517867fa
......@@ -5,7 +5,7 @@
# klici hasove tabulky jsou jmena potomku, hodnotami jmena rodicu
otec = dict(dana="milan", petr="milan", david="jan")
matka = dict(dana="pavla", petr="pavla", david="jana")
potomci = set(otec.keys() + matka.keys())
potomci = set(list(otec.keys()) + list(matka.keys()))
# pravidla
def rodic(x, y):
......
#!/usr/bin/env python
# encoding=utf-8 (pep 0263)
from __future__ import division
from linked_lists import LinkedList, Cons, Nil
from best_search import BestSearch
......@@ -24,10 +25,12 @@ def goes_before(T1, T2):
return False
def is_goal(state):
# zavisi na resenem problemu
waiting, _, _ = state
return waiting == Nil
def move_anyYC(state):
# zavisi na resenem problemu
tasks1, active, fin1 = state
_, f = active.head
active1 = active.tail
......
......@@ -3,7 +3,7 @@ Rozvrh prace procesoru, algoritmus A*
Pocatecni stav: ([('t1', 4), ('t2', 2), ('t3', 2), ('t4', 20), ('t5', 20), ('t6', 11), ('t7', 11)], [('idle', 0), ('idle', 0), ('idle', 0)], 0)
Nalezene reseni:
Prohledano 130 stavu, vysledne reseni ma cenu 24.
Prohledano 124 stavu, vysledne reseni ma cenu 24.
1: ([('t1', 4), ('t2', 2), ('t3', 2), ('t4', 20), ('t5', 20), ('t6', 11), ('t7', 11)], [('idle', 0), ('idle', 0), ('idle', 0)], 0)
2: ([('t2', 2), ('t3', 2), ('t4', 20), ('t5', 20), ('t6', 11), ('t7', 11)], [('idle', 0), ('idle', 0), ('t1', 4)], 4)
3: ([('t3', 2), ('t4', 20), ('t5', 20), ('t6', 11), ('t7', 11)], [('idle', 0), ('t2', 2), ('t1', 4)], 4)
......
......@@ -118,4 +118,6 @@ if __name__ == "__main__":
print(' goal(g).')
print(' goal(h).')
print('\nVysledky dotazu andor("a"):')
print(andor("a"))
solution = andor("a")
for key, value in sorted(solution.items()):
print("%s : %s" % (key, value))
......@@ -12,4 +12,8 @@ Prohledavani AND/OR grafu - implementace pomoci prioritni fronty
goal(h).
Vysledky dotazu andor("a"):
{'a': ('or_result', ['c']), 'h': 'goal', 'c': ('and_result', ['g', 'f']), 'g': 'goal', 'f': ('or_result', ['h'])}
a : ('or_result', ['c'])
c : ('and_result', ['g', 'f'])
f : ('or_result', ['h'])
g : goal
h : goal
......@@ -2,6 +2,7 @@
# encoding=utf-8 (pep 0263)
# je zapotrebi nainstaloval balicek python-constraint
# <https://github.com/python-constraint/python-constraint>
from constraint import Problem, AllDifferentConstraint
problem = Problem()
......
......@@ -38,5 +38,8 @@ if __name__ == "__main__":
print("CLP - Problem N dam\n")
print("Vysledek volani queens(4).getSolutions():")
print("------")
for solution in queens(4).getSolutions():
print(solution)
for key, value in sorted(solution.items()):
print("%s : %s" % (key, value))
print("------")
CLP - Problem N dam
Vysledek volani queens(4).getSolutions():
{'X2': 1, 'X3': 4, 'X1': 3, 'X4': 2}
{'X2': 4, 'X3': 1, 'X1': 2, 'X4': 3}
------
X1 : 3
X2 : 1
X3 : 4
X4 : 2
------
X1 : 2
X2 : 4
X3 : 1
X4 : 3
------
......@@ -9,26 +9,44 @@ IGNORED_PYLINT3_TESTS=
tests:
# all tests
@make -j 3 output pylint2 pylint3
@make -j 3 output2.7 output3.x pylint pylint3
# all tests ok
output:
# python output test
output2.7:
# python 2.7 output test
@set -e; \
TEMP=`mktemp`; \
trap 'rm $$TEMP' EXIT; \
for FILE in *.py; do \
printf '# python output test "%s"\n' "$$FILE"; \
printf '# python 2.7 output test "%s"\n' "$$FILE"; \
if [ -e "$$FILE.out" ]; then \
python "$$FILE" > $$TEMP; \
python2.7 "$$FILE" > $$TEMP; \
diff "$$FILE.out" $$TEMP; \
printf '# python output test "%s" ok\n' "$$FILE"; \
printf '# python 2.7 output test "%s" ok\n' "$$FILE"; \
else \
printf 'There exists no output for script %s!' "$$FILE"; \
exit 1; \
fi; \
done
# python output test ok
# python 2.7 output test ok
output3.x:
# python 3.x output test
@set -e; \
TEMP=`mktemp`; \
trap 'rm $$TEMP' EXIT; \
for FILE in *.py; do \
printf '# python 3.x output test "%s"\n' "$$FILE"; \
if [ -e "$$FILE.out" ]; then \
python3 "$$FILE" > $$TEMP; \
diff "$$FILE.out" $$TEMP; \
printf '# python 3.x output test "%s" ok\n' "$$FILE"; \
else \
printf 'There exists no output for script %s!' "$$FILE"; \
exit 1; \
fi; \
done
# python 3.x output test ok
COMMA:=,
EMPTY:=
......@@ -38,13 +56,13 @@ PYLINT2_OPTIONS=--disable=$(subst $(SPACE),$(COMMA),\
PYLINT3_OPTIONS=--disable=$(subst $(SPACE),$(COMMA),\
$(IGNORED_PYLINT_TESTS) $(IGNORED_PYLINT3_TESTS))
pylint2:
# pylint2 test
pylint:
# pylint test
@if ! REPORT="$$(pylint $(PYLINT2_OPTIONS) *.py 2>&1)"; then \
printf "%s\n" "$$REPORT"; \
exit 1; \
fi
# pylint2 test ok
# pylint test ok
pylint3:
# pylint3 test
......
......@@ -25,6 +25,12 @@ class Cons(object):
def __ne__(self, other):
return not self.__eq__(other)
def __lt__(self, other):
return self.head < other.head or self.tail < other.tail
def __gt__(self, other):
return self.head > other.head or self.tail > other.tail
def __iter__(self):
return _Iterator(self)
......@@ -49,8 +55,7 @@ class _Iterator(object):
self._linked_list = self._linked_list.tail
return head
def __next__(self):
return next(self)
__next__ = next
def LinkedList(lst):
result = Nil
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment