Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
trs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
trs
Commits
0ac438f3
Commit
0ac438f3
authored
Feb 27, 2012
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added basic validation functionality.
parent
566a7f5f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
15 deletions
+34
-15
src/validation.py
src/validation.py
+14
-15
tests/test_validation.py
tests/test_validation.py
+20
-0
No files found.
src/validation.py
View file @
0ac438f3
from
src.parser
import
Parser
from
tests.parser
import
ParserWrapper
class
ValidationNode
(
object
):
pass
from
src.possibilities
import
apply_suggestion
def
validate
(
exp
,
result
):
...
...
@@ -11,23 +8,25 @@ def validate(exp, result):
Validate that exp =>* result.
"""
parser
=
ParserWrapper
(
Parser
)
exp
=
parser
.
run
([
exp
])
result
=
parser
.
run
([
result
])
return
validate_graph
(
exp
,
result
)
return
traverse_preorder
(
parser
,
exp
,
result
)
def
iter_preorder
(
exp
,
possibility
):
def
traverse_preorder
(
parser
,
exp
,
result
):
"""
Traverse the possibility tree using pre-order traversal.
"""
pass
root
=
parser
.
run
([
exp
])
if
root
.
equals
(
result
):
return
root
def
validate_graph
(
exp
,
result
):
"""
Validate that "exp" =>* "result".
"""
# TODO: Traverse the tree of possibility applications
return
False
possibilities
=
parser
.
parser
.
possibilities
for
p
in
possibilities
:
child
=
apply_suggestion
(
root
,
p
)
next_root
=
traverse_preorder
(
parser
,
str
(
child
),
result
)
if
next_root
:
return
next_root
tests/test_validation.py
0 → 100644
View file @
0ac438f3
from
unittest
import
TestCase
from
src.validation
import
validate
class
TestValidation
(
TestCase
):
def
test_simple_success
(
self
):
self
.
assertTrue
(
validate
(
'3a+a'
,
'4a'
))
def
test_simple_failure
(
self
):
self
.
assertFalse
(
validate
(
'3a+a'
,
'4a+1'
))
def
test_intermediate_success
(
self
):
self
.
assertTrue
(
validate
(
'3a+a+b+2b'
,
'4a+3b'
))
def
test_intermediate_failure
(
self
):
self
.
assertFalse
(
validate
(
'3a+a+b+2b'
,
'4a+4b'
))
#def test_intermediate_failure(self):
# self.assertFalse(validate('(x-1)^3+(x-1)^3', '4a+4b'))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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