From ad9ddf5ab9e5503ef1f800778ec6c955c52e7df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Doar=C3=A9?= Date: Sat, 29 Mar 2025 17:43:09 +0100 Subject: [PATCH] Fix bug in circle_of_5ths_rotate if cmajor is not the strating scale --- scale.lua | 2 +- test/test_scale.lua | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/scale.lua b/scale.lua index 057e98e..7279e5c 100644 --- a/scale.lua +++ b/scale.lua @@ -115,7 +115,7 @@ end ]] function Scale:circle_of_5ths_rotate(iterations) local total_alterations = self:count_alterations()+iterations - local rotation = ( (total_alterations + 5) % 12 ) - 5 + local rotation = ( (total_alterations + 5) % 12 ) - 5 - self:count_alterations() if(rotation == 0) then return self elseif(rotation < 0) then diff --git a/test/test_scale.lua b/test/test_scale.lua index 132c015..92b8664 100644 --- a/test/test_scale.lua +++ b/test/test_scale.lua @@ -368,4 +368,10 @@ function TestScale:test_c5ths_rotate() luaunit.assertEquals(c_major:circle_of_5ths_rotate(-8), c_major:circle_of_5ths_rotate(4)) luaunit.assertEquals(c_major:circle_of_5ths_rotate(123), c_major:circle_of_5ths_rotate(3)) luaunit.assertEquals(c_major:circle_of_5ths_rotate(-123), c_major:circle_of_5ths_rotate(-3)) + + local next = c_major:circle_of_5ths_rotate(1) + for i = 1,11 do + next = next:circle_of_5ths_rotate(1) + end + luaunit.assertEquals(next, c_major) end