barelymusician/engine/conductor_test.cpp
// Tests that conductor returns notes as expected.
Tests that conductor returns notes as expected.
Tests that conductor returns notes as expected .
TEST(ConductorTest, GetNote) {
  const double kPitch = 0.25;
  const double kRootPitch = -1.75;
  const std::vector<double> kScale = {0.0, 0.2, 0.6, 0.75};
  Conductor conductor;
  EXPECT_DOUBLE_EQ(
      conductor.GetNote(Note::PitchDefinition::AbsolutePitch(kPitch)), kPitch);
  EXPECT_DOUBLE_EQ(
      conductor.GetNote(Note::PitchDefinition::RelativePitch(kPitch)), kPitch);
  for (int i = 0; i < static_cast<int>(kScale.size()); ++i) {
    EXPECT_DOUBLE_EQ(conductor.GetNote(Note::PitchDefinition::ScaleIndex(i)),
                     0.0);
    EXPECT_DOUBLE_EQ(conductor.GetNote(Note::PitchDefinition::ScaleIndex(-i)),
                     0.0);
  }
  conductor.SetRootNote(kRootPitch);
  EXPECT_DOUBLE_EQ(conductor.GetRootNote(), kRootPitch);
  EXPECT_DOUBLE_EQ(
      conductor.GetNote(Note::PitchDefinition::AbsolutePitch(kPitch)), kPitch);
  EXPECT_DOUBLE_EQ(
      conductor.GetNote(Note::PitchDefinition::RelativePitch(kPitch)),
      kRootPitch + kPitch);
  for (int i = 0; i < static_cast<int>(kScale.size()); ++i) {
    EXPECT_DOUBLE_EQ(conductor.GetNote(Note::PitchDefinition::ScaleIndex(i)),
                     kRootPitch);
    EXPECT_DOUBLE_EQ(conductor.GetNote(Note::PitchDefinition::ScaleIndex(-i)),
                     kRootPitch);
  }
  conductor.SetScale(kScale);
  EXPECT_EQ(std::vector<double>(conductor.GetScale().begin(),
                                conductor.GetScale().end()),
            kScale);
  EXPECT_DOUBLE_EQ(
      conductor.GetNote(Note::PitchDefinition::AbsolutePitch(kPitch)), kPitch);
  EXPECT_DOUBLE_EQ(
      conductor.GetNote(Note::PitchDefinition::RelativePitch(kPitch)),
      kRootPitch + kPitch);
  for (int i = 0; i < static_cast<int>(kScale.size()); ++i) {
    EXPECT_DOUBLE_EQ(conductor.GetNote(Note::PitchDefinition::ScaleIndex(i)),
                     kRootPitch + kScale[i]);
    EXPECT_DOUBLE_EQ(
        conductor.GetNote(Note::PitchDefinition::ScaleIndex(-i)),
        kRootPitch - (i > 0 ? 1.0 - kScale[kScale.size() - i] : 0.0));
  }
}
TEST ( ConductorTest , GetNote ) { const double kPitch = 0.25 ; const double kRootPitch = -1.75 ; const std :: vector < double > kScale = { 0.0 , 0.2 , 0.6 , 0.75 } ; Conductor conductor ; EXPECT_DOUBLE_EQ ( conductor . GetNote ( Note :: PitchDefinition :: AbsolutePitch ( kPitch ) ) , kPitch ) ; EXPECT_DOUBLE_EQ ( conductor . GetNote ( Note :: PitchDefinition :: RelativePitch ( kPitch ) ) , kPitch ) ; for ( int i = 0 ; i < static_cast < int > ( kScale . size ( ) ) ; ++ i ) { EXPECT_DOUBLE_EQ ( conductor . GetNote ( Note :: PitchDefinition :: ScaleIndex ( i ) ) , 0.0 ) ; EXPECT_DOUBLE_EQ ( conductor . GetNote ( Note :: PitchDefinition :: ScaleIndex ( - i ) ) , 0.0 ) ; } conductor . SetRootNote ( kRootPitch ) ; EXPECT_DOUBLE_EQ ( conductor . GetRootNote ( ) , kRootPitch ) ; EXPECT_DOUBLE_EQ ( conductor . GetNote ( Note :: PitchDefinition :: AbsolutePitch ( kPitch ) ) , kPitch ) ; EXPECT_DOUBLE_EQ ( conductor . GetNote ( Note :: PitchDefinition :: RelativePitch ( kPitch ) ) , kRootPitch + kPitch ) ; for ( int i = 0 ; i < static_cast < int > ( kScale . size ( ) ) ; ++ i ) { EXPECT_DOUBLE_EQ ( conductor . GetNote ( Note :: PitchDefinition :: ScaleIndex ( i ) ) , kRootPitch ) ; EXPECT_DOUBLE_EQ ( conductor . GetNote ( Note :: PitchDefinition :: ScaleIndex ( - i ) ) , kRootPitch ) ; } conductor . SetScale ( kScale ) ; EXPECT_EQ ( std :: vector < double > ( conductor . GetScale ( ) . begin ( ) , conductor . GetScale ( ) . end ( ) ) , kScale ) ; EXPECT_DOUBLE_EQ ( conductor . GetNote ( Note :: PitchDefinition :: AbsolutePitch ( kPitch ) ) , kPitch ) ; EXPECT_DOUBLE_EQ ( conductor . GetNote ( Note :: PitchDefinition :: RelativePitch ( kPitch ) ) , kRootPitch + kPitch ) ; for ( int i = 0 ; i < static_cast < int > ( kScale . size ( ) ) ; ++ i ) { EXPECT_DOUBLE_EQ ( conductor . GetNote ( Note :: PitchDefinition :: ScaleIndex ( i ) ) , kRootPitch + kScale [ i ] ) ; EXPECT_DOUBLE_EQ ( conductor . GetNote ( Note :: PitchDefinition :: ScaleIndex ( - i ) ) , kRootPitch - ( i > 0 ? 1.0 - kScale [ kScale . size ( ) - i ] : 0.0 ) ) ; } }
Tests that conductor returns notes as expected.
Tests that conductor returns notes as expected .
// Set root note. // Set scale.