File: test_musicalpitch.py

package info (click to toggle)
solfege 3.10.3-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 12,408 kB
  • ctags: 4,270
  • sloc: python: 22,161; xml: 7,536; ansic: 4,442; makefile: 685; sh: 308
file content (45 lines) | stat: -rw-r--r-- 1,620 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Solfege - free ear training software
# Copyright (C) 2007, 2008 Tom Cato Amundsen
# License is GPL, see file COPYING

import unittest
import doctest
import mpd.musicalpitch
from mpd.musicalpitch import MusicalPitch
from mpd.interval import Interval

class TestMusicalPitch(unittest.TestCase):
    def test_normalize_double_accidental(self):
        for a, b in (("c", "c"),
                     ("cisis", "d"),
                     ("disis", "e"),
                     ("eisis", "fis"),
                     ("fisis", "g"),
                     ("gisis", "a"),
                     ("aisis", "b"),
                     ("bisis", "cis'"),
                     ("ceses", "bes,"),
                     ("deses", "c"),
                     ("eses", "d"),
                     ("feses", "ees"),
                     ("geses", "f"),
                     ("ases", "g"),
                     ("beses", "a"),
                     ):
            n = MusicalPitch.new_from_notename(a)
            n.normalize_double_accidental()
            self.assertEquals(n.get_octave_notename(), b)
    def test_add(self):
        n = MusicalPitch.new_from_notename('c')
        n = n + 2
        self.assertEquals(n.get_octave_notename(), 'd')
    def test_add_integer_fail(self):
        n = MusicalPitch.new_from_int(120)
        self.assertRaises(ValueError, lambda: n + 20)
    def test_add_interval_fail(self):
        n = MusicalPitch.new_from_int(120)
        i = Interval("M10")
        self.assertRaises(ValueError, lambda: n + i)

suite = unittest.makeSuite(TestMusicalPitch)
suite.addTest(doctest.DocTestSuite(mpd.musicalpitch))