Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Allzweckmesser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
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
Messerschleifer
Allzweckmesser
Commits
97941839
Commit
97941839
authored
6 years ago
by
Simon Will
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for meters.py
parent
3f68e9fb
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
allzweckmesser/meters.py
+6
-5
6 additions, 5 deletions
allzweckmesser/meters.py
allzweckmesser/model.py
+1
-1
1 addition, 1 deletion
allzweckmesser/model.py
tests/test_meters.py
+65
-0
65 additions, 0 deletions
tests/test_meters.py
with
72 additions
and
6 deletions
allzweckmesser/meters.py
+
6
−
5
View file @
97941839
...
@@ -9,7 +9,7 @@ from .model import Reading, Position
...
@@ -9,7 +9,7 @@ from .model import Reading, Position
def
caesurae_together
(
position_specs
,
reward
):
def
caesurae_together
(
position_specs
,
reward
):
def
get_reward
(
meter
:
Meter
,
reading
:
Reading
):
def
get_reward
(
meter
:
Meter
,
reading
:
Reading
):
for
spec
in
position_specs
:
for
spec
in
position_specs
:
position
=
Position
.
after
(
spec
[
0
],
reading
,
meter
,
spec
[
1
])
position
=
Position
.
after
(
spec
[
0
],
reading
,
spec
[
1
]
,
meter
)
if
not
position
.
word_boundary
:
if
not
position
.
word_boundary
:
return
0
return
0
else
:
else
:
...
@@ -46,8 +46,9 @@ class Meter:
...
@@ -46,8 +46,9 @@ class Meter:
return
sum
(
cond
(
reading
)
for
cond
in
self
.
conditions
)
return
sum
(
cond
(
reading
)
for
cond
in
self
.
conditions
)
ALL_METERS
=
[
ALL_METERS
=
{
Meter
(
'
Catalectic Dactylic Hexameter
'
:
Meter
(
'
Catalectic Dactylic Hexameter
'
,
'
Catalectic Dactylic Hexameter
'
,
r
'
(–)(⏑⏑|–)(–)(⏑⏑|–)(–)(⏑⏑|–)(–)(⏑⏑|–)(–)(⏑⏑|–)(⏑|–)
'
,
r
'
(–)(⏑⏑|–)(–)(⏑⏑|–)(–)(⏑⏑|–)(–)(⏑⏑|–)(–)(⏑⏑|–)(⏑|–)
'
,
conditions
=
{
conditions
=
{
...
@@ -59,7 +60,7 @@ ALL_METERS = [
...
@@ -59,7 +60,7 @@ ALL_METERS = [
},
},
short_name
=
'
6da‸
'
short_name
=
'
6da‸
'
),
),
Meter
(
'
Iambic Trimeter
'
:
Meter
(
'
Iambic Trimeter
'
,
'
Iambic Trimeter
'
,
r
'
(⏑|⏑⏑|–)(⏑⏑|–)(⏑)(⏑⏑|–)(⏑|⏑⏑|–)(⏑⏑|–)(⏑)(⏑⏑|–)(⏑|⏑⏑|–)(⏑⏑|–)(⏑)(⏑|–)
'
,
r
'
(⏑|⏑⏑|–)(⏑⏑|–)(⏑)(⏑⏑|–)(⏑|⏑⏑|–)(⏑⏑|–)(⏑)(⏑⏑|–)(⏑|⏑⏑|–)(⏑⏑|–)(⏑)(⏑|–)
'
,
conditions
=
{
conditions
=
{
...
@@ -68,4 +69,4 @@ ALL_METERS = [
...
@@ -68,4 +69,4 @@ ALL_METERS = [
},
},
short_name
=
'
3ia
'
short_name
=
'
3ia
'
),
),
]
}
This diff is collapsed.
Click to expand it.
allzweckmesser/model.py
+
1
−
1
View file @
97941839
...
@@ -499,7 +499,7 @@ class Position:
...
@@ -499,7 +499,7 @@ class Position:
@classmethod
@classmethod
def
after
(
cls
,
type
:
str
,
reading
:
Reading
,
position_number
:
int
,
def
after
(
cls
,
type
:
str
,
reading
:
Reading
,
position_number
:
int
,
meter
:
'
.meters.Meter
'
)
->
'
Position
'
:
meter
:
'
.meters.Meter
'
)
->
'
Position
'
:
if
type
==
'
mora
'
:
if
type
==
'
mora
'
:
return
cls
.
after_mora
(
reading
,
position_number
)
return
cls
.
after_mora
(
reading
,
position_number
)
elif
type
==
'
element
'
:
elif
type
==
'
element
'
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_meters.py
0 → 100644
+
65
−
0
View file @
97941839
# -*- coding: utf-8 -*-
import
os.path
import
re
import
pytest
import
allzweckmesser
as
azm
TEST_DIR
=
os
.
path
.
dirname
(
__file__
)
RE_MATCH_TYPE
=
type
(
re
.
match
(
'
a
'
,
'
a
'
))
@pytest.fixture
def
verse_models
():
verse_filepath
=
os
.
path
.
join
(
TEST_DIR
,
'
verses.json
'
)
verse_models
=
azm
.
model
.
from_json
(
verse_filepath
)
return
verse_models
@pytest.fixture
def
pentameter_verse
(
verse_models
):
return
verse_models
[
2
]
@pytest.fixture
def
hexameter_verse
(
verse_models
):
return
verse_models
[
3
]
@pytest.fixture
def
hexameter
():
return
azm
.
meters
.
ALL_METERS
[
'
Catalectic Dactylic Hexameter
'
]
def
test_caesura_together
(
hexameter
,
hexameter_verse
):
reading
=
hexameter_verse
.
readings
[
0
]
penthemimeral_reward
=
azm
.
meters
.
caesurae_together
(
[(
'
mora
'
,
10
,
'
Penthemimeral
'
)],
1
)
assert
penthemimeral_reward
(
hexameter
,
reading
)
==
1
trithemimeral_reward
=
azm
.
meters
.
caesurae_together
(
[(
'
mora
'
,
6
,
'
Trithemimeral
'
)],
1
)
assert
trithemimeral_reward
(
hexameter
,
reading
)
==
0
hephthemimeral_reward
=
azm
.
meters
.
caesurae_together
(
[(
'
mora
'
,
14
,
'
Hephthemimeral
'
)],
1
)
assert
hephthemimeral_reward
(
hexameter
,
reading
)
==
1
trit_and_hepht_hemimeral_reward
=
azm
.
meters
.
caesurae_together
(
[(
'
mora
'
,
6
,
'
Hephthemimeral
'
),
(
'
mora
'
,
14
,
'
Hephthemimeral
'
)],
1
)
assert
trit_and_hepht_hemimeral_reward
(
hexameter
,
reading
)
==
0
def
test_match_reading_success
(
hexameter
,
hexameter_verse
):
match
=
hexameter
.
match_reading
(
hexameter_verse
.
readings
[
0
])
assert
isinstance
(
match
,
RE_MATCH_TYPE
)
def
test_match_reading_fail
(
hexameter
,
pentameter_verse
):
match
=
hexameter
.
match_reading
(
pentameter_verse
.
readings
[
0
])
assert
match
is
None
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