Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
trs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
trs
Commits
0ac438f3
Commit
0ac438f3
authored
13 years ago
by
Sander Mathijs van Veen
Browse files
Options
Downloads
Patches
Plain Diff
Added basic validation functionality.
parent
566a7f5f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/validation.py
+14
-15
14 additions, 15 deletions
src/validation.py
tests/test_validation.py
+20
-0
20 additions, 0 deletions
tests/test_validation.py
with
34 additions
and
15 deletions
src/validation.py
+
14
−
15
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
This diff is collapsed.
Click to expand it.
tests/test_validation.py
0 → 100644
+
20
−
0
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'))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment