def test_Name_set(self): s = ScaleKey() keys = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11} for k, kp in keys.items(): for acc_count in range(1, 4): for a, ap in Accidental.Accidentals.items(): name = k + a * acc_count pitch = PitchClass.Get(kp + (ap * acc_count))[0] with self.subTest(name=name): s.Name = name self.assertEqual(name, s.Name) self.assertEqual(pitch, s.PitchClass)
def test_init_set(self): k = ScaleKey('A') s = Scale(k, ScaleIntervals.Minor) self.assertEqual(k, s.Key) self.assertEqual('A', s.Key.Name) self.assertEqual(9, s.Key.PitchClass) self.assertEqual(ScaleIntervals.Minor, s.Intervals) # self.assertEqual([9,11,0,2,4,5,7], s.PitchClasses) self.assertEqual([(9,0),(11,0),(0,1),(2,1),(4,1),(5,1),(7,1)], s.PitchClasses)
def __init__(self, keyName='C', intervals=ScaleIntervals.Major): self.__ValidateInterval(intervals) self.__intervals = intervals self.__pitchClasses = [] self.__names = [] self.__scaleKey = None self.__scaleKey = ScaleKey(keyName, self) self.__calcPitchClasses() self.Key.Name = keyName
def __init__(self, scaleKey=None, intervals=ScaleIntervals.Major): if None is scaleKey: self.__scaleKey = ScaleKey('C') else: if not isinstance(scaleKey, ScaleKey): raise TypeError( f'引数scaleKeyはScaleKey型にしてください。: type(scaleKey)={type(scaleKey)}' ) self.__scaleKey = weakref.proxy(scaleKey) # self.__key = key self.__intervals = None self.__pitchClasses = [] self.__names = [] self.Intervals = intervals
def __init__(self, keyName='C', intervals=ScaleIntervals.Major): # def __init__(self, key=0, intervals=ScaleIntervals.Major): # def __init__(self, scaleKey=None, intervals=ScaleIntervals.Major): # if None is scaleKey: self.__scaleKey = ScaleKey('C') # else: # if not isinstance(scaleKey, ScaleKey): raise TypeError(f'引数scaleKeyはScaleKey型にしてください。: type(scaleKey)={type(scaleKey)}') # self.__scaleKey = weakref.proxy(scaleKey) # self.__key = key # if not isinstance(observer, Scale): raise TypeError('引数observerはScale型にしてください。: type(observer)={type(observer)}') # self.__observer = observer # self.__key = PitchClass.Get(Key.Get(v))[0] # self.__intervals = None self.__ValidateInterval(intervals) self.__intervals = intervals self.__pitchClasses = [] self.__names = [] self.__scaleKey = ScaleKey(keyName, self)
def test_PitchClass_set(self): s = ScaleKey() with self.assertRaises(AttributeError) as ex: s.PitchClass = 0 self.assertIn("can't set attribute", str(ex.exception))
def test_Name_set_int(self): s = ScaleKey() with self.assertRaises(TypeError) as ex: s.Name = 0 self.assertIn('引数nameはstr型にしてください。', str(ex.exception))
def test_init_Invalid_Value_Name(self): with self.assertRaises(ValueError) as ex: s = ScaleKey('無効値') self.assertIn('keyは次のうちのいずれかにしてください。', str(ex.exception))
def test_init_Invalid_Type_Name(self): with self.assertRaises(TypeError) as ex: s = ScaleKey(0) self.assertIn('引数nameはstr型にしてください。', str(ex.exception))
def test_init_Default(self): s = ScaleKey() self.assertEqual('C', s.Name) self.assertEqual(0, s.PitchClass)