| Trees | Indices | Help |
|
|---|
|
|
1 """Unit tests for jazzparser.formalisms.music_halfspan.rules. 2 3 """ 4 """ 5 ============================== License ======================================== 6 Copyright (C) 2008, 2010-12 University of Edinburgh, Mark Granroth-Wilding 7 8 This file is part of The Jazz Parser. 9 10 The Jazz Parser is free software: you can redistribute it and/or modify 11 it under the terms of the GNU General Public License as published by 12 the Free Software Foundation, either version 3 of the License, or 13 (at your option) any later version. 14 15 The Jazz Parser is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with The Jazz Parser. If not, see <http://www.gnu.org/licenses/>. 22 23 ============================ End license ====================================== 24 25 """ 26 __author__ = "Mark Granroth-Wilding <mark.granroth-wilding@ed.ac.uk>" 27 28 import unittest, os 29 30 from jazzparser.formalisms.music_halfspan.syntax import sign_from_string 31 from jazzparser.formalisms.music_halfspan.rules import ApplicationRule 32 from jazzparser.grammar import get_grammar 3335 """ 36 Tests for the application rule. 37 38 """82 8340 # Load a grammar 41 self.grammar = get_grammar() 42 self.fapply = self.grammar.rules_by_name['appf'] 43 self.bapply = self.grammar.rules_by_name['appb']4446 # An application that should succeed 47 sign0 = sign_from_string(r"V^D / I^DT : \$x.leftonto($x)") 48 sign1 = sign_from_string(r"I^T : [<0,0>]") 49 results = self.fapply.apply_rule([sign0, sign1]) 50 # Check this gave the expected result 51 correct = sign_from_string(r"V^D - I^T : [leftonto(<0,0>)]") 52 self.assertIsNotNone(results, 53 msg="rule application failed: %s on %s and %s" % (self.fapply, sign0, sign1)) 54 self.assertEqual(results[0], correct)5557 # An application that should fail 58 sign0 = sign_from_string(r"V^D \ I^DT : \$x.leftonto($x)") 59 sign1 = sign_from_string(r"I^T : [<0,0>]") 60 results = self.fapply.apply_rule([sign0, sign1]) 61 # Check this failed as expected 62 self.assertEqual(results, None)6365 # An application that should succeed 66 sign0 = sign_from_string(r"III^T : [<0,1>]") 67 sign1 = sign_from_string(r"IV^T \ III^T : \$x.$x") 68 results = self.bapply.apply_rule([sign0, sign1]) 69 # Check this gave the expected result 70 correct = sign_from_string(r"III^T - IV^T : [<0,1>]") 71 self.assertIsNotNone(results, 72 msg="rule application failed: %s on %s and %s" % (self.bapply, sign0, sign1)) 73 self.assertEqual(results[0], correct)7476 # An application that should fail 77 sign0 = sign_from_string(r"V^D / I^DT : \$x.leftonto($x)") 78 sign1 = sign_from_string(r"I^T : [<0,0>]") 79 results = self.bapply.apply_rule([sign0, sign1]) 80 # Check this failed as expected 81 self.assertEqual(results, None)85 """ 86 Tests for the composition rule. 87 88 @todo: Write these tests. I'm bored of writing dull tests right now. 89 90 """9193 """ 94 Tests for the development rule. 95 96 """12098 # Load a grammar 99 self.grammar = get_grammar() 100 self.devel = self.grammar.rules_by_name['dev']101103 # An application that should succeed 104 sign0 = sign_from_string(r"bVII^D - III^T : [leftonto(<1,2>), <3,4>]") 105 sign1 = sign_from_string(r"I^T : [<0,0>]") 106 results = self.devel.apply_rule([sign0, sign1]) 107 # Check this gave the expected result 108 correct = sign_from_string(r"bVII^D - I^T : [leftonto(<1,2>), <3,4>, <0,0>]") 109 self.assertIsNotNone(results, 110 msg="rule application failed: %s on %s and %s" % (self.devel, sign0, sign1)) 111 self.assertEqual(results[0], correct)112114 # An application that should fail 115 sign0 = sign_from_string(r"V^D / I^DT : \$x.leftonto($x)") 116 sign1 = sign_from_string(r"I^T : [<0,0>]") 117 results = self.devel.apply_rule([sign0, sign1]) 118 # Check this failed as expected 119 self.assertEqual(results, None)122 """ 123 Tests for the coordination rule. 124 125 """149127 # Load a grammar 128 self.grammar = get_grammar() 129 self.coord = self.grammar.rules_by_name['coord']130132 # An application that should succeed 133 sign0 = sign_from_string(r"bVII^D /{c} III^TD : \$x.leftonto(leftonto($x))") 134 sign1 = sign_from_string(r"IV^D /{c} III^T : \$y.leftonto($y)") 135 results = self.coord.apply_rule([sign0, sign1]) 136 # Check this gave the expected result 137 correct = sign_from_string(r"bVII^D /{c} III^T : (\$x.leftonto(leftonto($x))) & (\$y.leftonto($y))") 138 self.assertIsNotNone(results, 139 msg="rule application failed: %s on %s and %s" % (self.coord, sign0, sign1)) 140 self.assertEqual(results[0], correct)141143 # An application that should fail 144 sign0 = sign_from_string(r"V^D / I^DT : \$x.leftonto($x)") 145 sign1 = sign_from_string(r"I^T : [<0,0>]") 146 results = self.coord.apply_rule([sign0, sign1]) 147 # Check this failed as expected 148 self.assertEqual(results, None)
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Mon Nov 26 16:05:02 2012 | http://epydoc.sourceforge.net |