Created
April 17, 2018 23:54
-
-
Save mewa/c97c4640987e800c263b0d7bf7ef21a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main :: IO () | |
main = hspec $ do | |
esacParser | |
midiConverter | |
esacParser = describe "ESAC parser" $ do | |
context "octave parsing" $ do | |
it "parses higher octave" $ do | |
property $ \(NonNegative n) -> parse parseOctave "" (replicate n '+') === (Right n) | |
it "parses lower octave" $ do | |
property $ \(NonNegative n) -> parse parseOctave "" (replicate n '-') === (Right (-n)) | |
it "parses mixed octave" $ do | |
property $ \(NonNegative a) (NonNegative b) -> | |
parse parseOctave "" (replicate a '+' ++ replicate b '-') === (Right (a - b)) | |
midiConverter = describe "ESAC-MIDI converter" $ do | |
it "MIDI -> ESAC -> MIDI = identity" $ do | |
forAll (listOf1 $ choose (1, (7 :: Int))) $ | |
\melodyNotes -> | |
let melody = (concat (fmap show melodyNotes)) ++ " //" | |
key = "10101a 04 C 3/4" | |
-- create example ESAC | |
(Right exampleEsac) = do | |
mel <- parse parseMelody "Invalid melody (MEL)" $ melody | |
key <- parse parseKey "Invalid key (KEY)" $ key | |
return $ Esac key mel | |
-- create example midi | |
exampleMidi = runReader (midiFromEsac 90 5) $ exampleEsac | |
-- get converted Esac from example midi | |
(Right convertedEsac) = esacFromMidiBytes (Sound C None) 90 5 $ midiBytes exampleMidi | |
-- get Midi from converted esac | |
newMidi = runReader (midiFromEsac 90 5) convertedEsac | |
in tracks exampleMidi === tracks newMidi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment