-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
108 additions
and
81 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,38 @@ | ||
(ns why-does-that-sound-good.algo.chord-test | ||
(:require [clojure.test :refer [deftest is are]] | ||
[why-does-that-sound-good.algo.chord :as chord])) | ||
(:require | ||
[clojure.test :refer [deftest are]] | ||
[why-does-that-sound-good.pitch :as pitch] | ||
[why-does-that-sound-good.algo.chord :as chord])) | ||
|
||
(deftest find-closest-octave-test | ||
(is (= 4 (chord/find-closest-octave :C 60))) | ||
(is (= 3 (chord/find-closest-octave :B 60)))) | ||
(are [pitch closest-note expected-closest-octave] (= expected-closest-octave (chord/find-closest-octave pitch closest-note)) | ||
:C (pitch/note :C4) 4 | ||
:B (pitch/note :C4) 3)) | ||
|
||
(deftest get-relative-chord-notes-test | ||
(are [expected-notes original-notes chord-pitches] (= expected-notes (chord/get-relative-chord-notes original-notes chord-pitches)) | ||
'(60 64 67) [60 64 67] #{:C :E :G} | ||
'(60 64 67 71) [60 64 67] #{:C :E :G :B} | ||
'(60 64 67) [60 64 67 71] #{:C :E :G} | ||
'(60 64 67 72) [60 64 67 72] #{:C :E :G})) | ||
(are [original-notes chord-pitches expected-notes] (= expected-notes (chord/get-relative-chord-notes original-notes chord-pitches)) | ||
[60 64 67] #{:C :E :G} '(60 64 67) | ||
[60 64 67] #{:C :E :G :B} '(60 64 67 71) | ||
[60 64 67 71] #{:C :E :G} '(60 64 67) | ||
[60 64 67 72] #{:C :E :G} '(60 64 67 72))) | ||
|
||
(deftest block->chords-test | ||
(are [block expected-chords] (= expected-chords (chord/block->chords block :find-closest? true)) | ||
{:id 1 :notes #{60 64 67}} '({:root :C | ||
:chord-type :maj | ||
:chord-pitches #{:C :G :E} | ||
:similarity 1 | ||
:original-block-id 1 | ||
:lowest-note-root? 1 | ||
:chord-pitches->readable-intervals {:C :1 :G :5 :E :M3} | ||
:chord-notes (60 64 67)} | ||
{:root :E | ||
:chord-type :m+5 | ||
:chord-pitches #{:E :G :C} | ||
:similarity 1 | ||
:original-block-id 1 | ||
:lowest-note-root? 0 | ||
:chord-pitches->readable-intervals {:E :1 :G :m3 :C :+5} | ||
:chord-notes (60 64 67)}) | ||
|
||
{:id 1 :notes #{}} nil)) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(ns why-does-that-sound-good.test-utils | ||
(:require | ||
[why-does-that-sound-good.algo.chord :as chord] | ||
[why-does-that-sound-good.pitch :as pitch])) | ||
|
||
(defn chord->example-notes [root chord-type] | ||
(->> {:root root :chord-type chord-type} | ||
chord/ALL-CHORDS | ||
(map #(pitch/construct-note % 4)))) | ||
|
||
(def c-major-blocks | ||
(map-indexed (fn [i [root chord-type]] | ||
{:id i :notes (chord->example-notes root chord-type)}) | ||
[[:C :maj] | ||
[:D :min] | ||
[:E :min] | ||
[:F :maj] | ||
[:G :maj] | ||
[:A :min] | ||
[:B :dim]])) |
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