Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Vít Novotný
pb016-priklady
Commits
0b2d2158
Commit
0b2d2158
authored
Jan 28, 2017
by
Vít Novotný
Browse files
added python 3.x tests and better python 3.x support
parent
517867fa
Changes
10
Hide whitespace changes
Inline
Side-by-side
1.1_13.py
View file @
0b2d2158
...
...
@@ -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
):
...
...
4.2_17.py
View file @
0b2d2158
#!/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
...
...
4.2_17.py.out
View file @
0b2d2158
...
...
@@ -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 1
30
stavu, vysledne reseni ma cenu 24.
Prohledano 1
24
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)
...
...
5.3_15-priority-queue.py
View file @
0b2d2158
...
...
@@ -118,4 +118,6 @@ if __name__ == "__main__":
print
(
' goal(g).'
)
print
(
' goal(h).'
)
print
(
'
\n
Vysledky dotazu andor("a"):'
)
print
(
andor
(
"a"
))
solution
=
andor
(
"a"
)
for
key
,
value
in
sorted
(
solution
.
items
()):
print
(
"%s : %s"
%
(
key
,
value
))
5.3_15-priority-queue.py.out
View file @
0b2d2158
...
...
@@ -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
6.2_11.py
View file @
0b2d2158
...
...
@@ -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
()
...
...
6.3_14.py
View file @
0b2d2158
...
...
@@ -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
(
"------"
)
6.3_14.py.out
View file @
0b2d2158
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
------
Makefile
View file @
0b2d2158
...
...
@@ -9,26 +9,44 @@ IGNORED_PYLINT3_TESTS=
tests
:
# all tests
@
make
-j
3 output pylint
2
pylint3
@
make
-j
3 output
2.7 output3.x
pylint pylint3
# all tests ok
output
:
# python output test
output
2.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
;
\
python
2.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)
)
pylint
2
:
# pylint
2
test
pylint
:
# pylint test
@
if
!
REPORT
=
"
$$
(pylint
$(PYLINT2_OPTIONS)
*.py 2>&1)"
;
then
\
printf
"%s
\n
"
"
$$
REPORT"
;
\
exit
1
;
\
fi
# pylint
2
test ok
# pylint test ok
pylint3
:
# pylint3 test
...
...
linked_lists.py
View file @
0b2d2158
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment