<commit_before>require 'test/unit'
require 'music-theory'

class TestNote < Test::Unit::TestCase
  include MusicTheory

  def test_basics
    c = Note.C
    assert_equal 0, c.diatonic_index
    assert_equal 0, c.accidentals

    fs = Note.Fs
    assert_equal 3, fs.diatonic_index
    assert_equal 1, fs.accidentals

    bb = Note.Bb
    assert_equal 6, bb.diatonic_index
    assert_equal -1, bb.accidentals
  end

  def test_octave
    assert_nil Note.C.octave
    assert_equal 4, Note.C(4).octave
  end

  def test_equality
    assert_not_equal Note.C, Note.Cs
    assert_equal Note.C(4), Note.C(4)
    assert_not_equal Note.C(4), Note.C(5)
    assert_equal Note.C, Note.C(4)
    assert_equal Note.C(4), Note.C
    assert_equal Note.C(5), Note.C(4) + Interval.octave
    assert_not_equal Note.C(5), Note.C(4) + Interval.octave(2)
  end

  def test_chromatic_index
    assert_equal 0, Note.C.chromatic_index
    assert_equal 1, Note.Cs.chromatic_index
    assert_equal 1, Note.Db.chromatic_index
    assert_equal 1, Note.C.sharp.chromatic_index
    assert_equal 2, Note.C.sharp(2).chromatic_index
    assert_equal -1, Note.C.flat.chromatic_index
    assert_equal 11, Note.B.chromatic_index
    assert_equal 12, Note.B.sharp.chromatic_index
    assert_equal 13, Note.B.sharp(2).chromatic_index
  end

  def test_interval_addition
    assert_equal Note.C, Note.C + 0
    assert_equal Note.D, Note.C + 1
    assert_equal Note.C, Note.C + Interval.unison
    assert_equal Note.D, Note.C + Interval.major(2)
    assert_equal Note.Db, Note.C + Interval.minor(2)
    assert_equal Note.Fs, Note.E + Interval.major(2)
    assert_equal Note.E, Note.A + Interval.perfect(5)
  end

end<commit_msg>Some more tests of note addition and subtraction<commit_after>require 'test/unit'
require 'music-theory'

class TestNote < Test::Unit::TestCase
  include MusicTheory

  def test_basics
    c = Note.C
    assert_equal 0, c.diatonic_index
    assert_equal 0, c.accidentals

    fs = Note.Fs
    assert_equal 3, fs.diatonic_index
    assert_equal 1, fs.accidentals

    bb = Note.Bb
    assert_equal 6, bb.diatonic_index
    assert_equal -1, bb.accidentals
  end

  def test_octave
    assert_nil Note.C.octave
    assert_equal 4, Note.C(4).octave
  end

  def test_equality
    assert_not_equal Note.C, Note.Cs
    assert_equal Note.C(4), Note.C(4)
    assert_not_equal Note.C(4), Note.C(5)
    assert_equal Note.C, Note.C(4)
    assert_equal Note.C(4), Note.C
    assert_equal Note.C(5), Note.C(4) + Interval.octave
    assert_not_equal Note.C(5), Note.C(4) + Interval.octave(2)
  end

  def test_chromatic_index
    assert_equal 0, Note.C.chromatic_index
    assert_equal 1, Note.Cs.chromatic_index
    assert_equal 1, Note.Db.chromatic_index
    assert_equal 1, Note.C.sharp.chromatic_index
    assert_equal 2, Note.C.sharp(2).chromatic_index
    assert_equal -1, Note.C.flat.chromatic_index
    assert_equal 11, Note.B.chromatic_index
    assert_equal 12, Note.B.sharp.chromatic_index
    assert_equal 13, Note.B.sharp(2).chromatic_index
  end

  def test_interval_addition_and_subtraction
    assert_equal Note.C, Note.C + 0
    assert_equal Note.D, Note.C + 1
    assert_equal Note.C, Note.C + Interval.unison
    assert_equal Note.D, Note.C + Interval.major(2)
    assert_equal Note.Db, Note.C + Interval.minor(2)
    assert_equal Note.Fs, Note.E + Interval.major(2)
    assert_equal Note.E, Note.A + Interval.perfect(5)
    assert_equal Note.Cb, Note.B.sharp(56) + Interval.diminished(2, 57)
    assert_equal Note.G, Note.D - Interval.perfect(5)
    assert_equal Note.Gs, Note.D - Interval.diminished(5)
    assert_equal Note.Gs, Note.D + Interval.diminished(-5)
  end

end
{'fraction_non_alphanumeric': 0.09907205240174673, 'fraction_numerical': 0.023471615720524017, 'mean_word_length': 3.3997599039615847, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5786360', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1358, 'n_words': 287}