def test_GetOctave_ZERO_OutOfRange_UP(self): lowerLimit = 0 with self.assertRaises(ValueError) as e: NoteName.Get('C11', lowerLimit) self.assertIn( f"lowerLimit={lowerLimit}のときoctaveは{lowerLimit}〜{lowerLimit+10}までです。", str(e.exception))
def test_Get_Invalid_Format(self): with self.assertRaises(ValueError) as e: NoteName.Get('無効値') self.assertIn('引数nameが有効な書式ではありません。', str(e.exception)) with self.assertRaises(ValueError) as e: NoteName.Get('C') self.assertIn('引数nameが有効な書式ではありません。', str(e.exception)) with self.assertRaises(ValueError) as e: NoteName.Get('c1') self.assertIn('引数nameが有効な書式ではありません。', str(e.exception)) with self.assertRaises(ValueError) as e: NoteName.Get('C--1') self.assertIn('引数nameが有効な書式ではありません。', str(e.exception)) with self.assertRaises(ValueError) as e: NoteName.Get('C+-1') self.assertIn('引数nameが有効な書式ではありません。', str(e.exception))
def test_GetOctave_YAMAHA_OutOfRange_LOW(self): lowerLimit = -2 with self.assertRaises(ValueError) as e: NoteName.Get('C-3', lowerLimit) typ = 'SPN' self.assertIn( f"lowerLimit={lowerLimit}のときoctaveは{lowerLimit}〜{lowerLimit+10}までです。", str(e.exception))
def test_Get_ZERO(self): lowerLimit = 0 self.assertEqual(0, NoteName.Get('C0', lowerLimit)) self.assertEqual(69, NoteName.Get('A5', lowerLimit)) self.assertEqual(127, NoteName.Get('G10', lowerLimit)) for k in Key.Keys.keys(): for o in range(lowerLimit, lowerLimit+10, 1): with self.subTest(key=k, octave=o): octave = o + abs(lowerLimit) if lowerLimit < 0 else o - abs(lowerLimit) expected = PitchClass.Get(Key.Get(k))[0] + (octave * (PitchClass.Max+1)) self.assertEqual(expected, NoteName.Get(k + str(o), lowerLimit)) expected = PitchClass.Get(Key.Get(k)+1)[0] + (octave * (PitchClass.Max+1)) self.assertEqual(expected, NoteName.Get(k + '#' + str(o), lowerLimit)) expected = PitchClass.Get(Key.Get(k)-1)[0] + (octave * (PitchClass.Max+1)) self.assertEqual(expected, NoteName.Get(k + 'b' + str(o), lowerLimit))
def test_Get_SPN(self): self.assertEqual(0, NoteName.Get('C-1')) self.assertEqual(69, NoteName.Get('A4')) self.assertEqual(127, NoteName.Get('G9')) lowerLimit = -1 for k in Key.Keys: for o in range(lowerLimit, lowerLimit + 10, 1): with self.subTest(key=k, octave=o): octave = o + abs( lowerLimit) if lowerLimit < 0 else o - abs(lowerLimit) expected = PitchClass.Get( Key.Get(k))[0] + (octave * (PitchClass.Max + 1)) self.assertEqual(expected, NoteName.Get(k + str(o))) expected = PitchClass.Get(Key.Get(k) + 1)[0] + (octave * (PitchClass.Max + 1)) self.assertEqual(expected, NoteName.Get(k + '#' + str(o))) expected = PitchClass.Get(Key.Get(k) - 1)[0] + (octave * (PitchClass.Max + 1)) self.assertEqual(expected, NoteName.Get(k + 'b' + str(o)))
def test_Get_Invalid_Type(self): with self.assertRaises(TypeError) as e: NoteName.Get(100) self.assertIn('引数nameはstr型にしてください。', str(e.exception))
def test_GetOctave_Invalid_Type(self): with self.assertRaises(TypeError) as e: NoteName.Get('C0', '無効値') self.assertIn(f"引数lowerLimitはint型にしてください。", str(e.exception))