#!/usr/bin/env python

import numpy as np


from DataSounds.sounds import build_scale, note_number, note_name


def test_build_scale_major():
    scale = build_scale('C', 'major', 1)
    assert scale == 'c d e f g a b'.split()


def test_build_scale_minor():
    scale = build_scale('A', 'minor', 1)
    assert scale == 'a b c d e f g'.split()


def test_build_scale_pentatonic():
    scale = build_scale('C', 'pentatonic', 1)
    assert scale == ['c', 'd', 'e', 'g', 'a']


def test_build_scale_pentatonic_two_octaves():
    scale = build_scale('D', 'pentatonic', 2)
    assert scale == ['d', 'e', 'f#', 'a', 'b', "d'", "e'", "f#'", "a'", "b'"]


def test_note_number():
    scale = build_scale('C', 'major', 1)
    assert all(note_number([1, 2, 3, 4], scale) == [0, 2, 4, 6])


def test_build_note_name():
    scale = build_scale('C', 'major', 1)
    notes = note_number([1, 2, 3, 4, np.nan], scale)
    assert [note_name(x, scale) for x in notes] == ['c', 'e', 'g', 'b', 'r']

#!/usr/bin/env python

import numpy as np


from DataSounds.sounds import build_scale, note_number, note_name, get_music


def test_build_scale_major():
    scale = build_scale('C', 'major', 1)
    assert scale == 'c d e f g a b'.split()


def test_build_scale_minor():
    scale = build_scale('A', 'minor', 1)
    assert scale == 'a b c d e f g'.split()


def test_build_scale_pentatonic():
    scale = build_scale('C', 'pentatonic', 1)
    assert scale == ['c', 'd', 'e', 'g', 'a']


def test_build_scale_pentatonic_two_octaves():
    scale = build_scale('D', 'pentatonic', 2)
    assert scale == ['d', 'e', 'f#', 'a', 'b', "d'", "e'", "f#'", "a'", "b'"]


def test_note_number():
    scale = build_scale('C', 'major', 1)
    assert all(note_number([1, 2, 3, 4], scale) == [0, 2, 4, 6])


def test_build_note_name():
    scale = build_scale('C', 'major', 1)
    notes = note_number([1, 2, 3, 4, np.nan], scale)
    assert [note_name(x, scale) for x in notes] == ['c', 'e', 'g', 'b', 'r']


def test_get_music():
    series = np.random.rand(24).reshape(2, 12)
    m = get_music(series, key='D', mode='pentatonic',
                  octaves=2, instruments=[0, 23])
    # TODO: how to test this? m is a StringIO containing a MIDI file.
    # Load the MIDI file and check what was generated?

Add test for get_music, but need more work