Last active
November 17, 2021 12:10
-
-
Save henryhamon/38aae5a621bf29f3ea63d602b966249b to your computer and use it in GitHub Desktop.
CodeGolf Encoder
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
Class dc.golf.Encoder | |
{ | |
ClassMethod Compress(coordinates As %String) As %String | |
{ | |
Quit "" | |
} | |
} |
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
/// test case | |
Class dc.golf.Test.Encoder Extends %UnitTest.TestCase | |
{ | |
Method Test2IdenticalNumbers() | |
{ | |
Do $$$AssertEquals(##class(dc.golf.Encoder).Compress("1,2,2,3"), "1,2*2,3") | |
Do $$$AssertEquals(##class(dc.golf.Encoder).Compress("22,22"), "22*2") | |
} | |
Method Test3ConsecutiveNumbersAsc() | |
{ | |
Do $$$AssertEquals(##class(dc.golf.Encoder).Compress("1,3,4,5,7"), "1,3-5,7") | |
} | |
Method Test3ConsecutiveNumbersDesc() | |
{ | |
Do $$$AssertEquals(##class(dc.golf.Encoder).Compress("1,5,4,3,7"), "1,5-3,7") | |
} | |
Method Test3NumbersSameIntervalDesc() | |
{ | |
Do $$$AssertEquals(##class(dc.golf.Encoder).Compress("1,10,8,6,7"), "1,10-6/2,7") | |
} | |
Method Test2IdenticalNegativeNumbers() | |
{ | |
Do $$$AssertEquals(##class(dc.golf.Encoder).Compress("-2,-2"), "-2*2") | |
} | |
Method TestDescendingFromPositiveToNegative() | |
{ | |
Do $$$AssertEquals(##class(dc.golf.Encoder).Compress("1,-1,-3,-5"), "1--5/2") | |
} | |
Method TestIdenticalConsecutive() | |
{ | |
Do $$$AssertEquals(##class(dc.golf.Encoder).Compress("1,1,2,3,4,5,7,9"), "1*2,2-5,7,9") | |
} | |
Method TestIdenticalConsecutiveSameInterval() | |
{ | |
Do $$$AssertEquals(##class(dc.golf.Encoder).Compress("1,1,2,3,4,5,7,9,11"), "1*2,2-5,7-11/2") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment