Created
July 1, 2021 00:39
-
-
Save henryhamon/e0dfd4c747d35e252a66c01bd562f047 to your computer and use it in GitHub Desktop.
Template and UnitTest to CodeGolf "If you can read this..."
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 CodeGolf.NatoTranslator | |
{ | |
ClassMethod ToNato(strin As %String) As %String | |
{ | |
Set strout = "" | |
// action | |
Quit strout | |
} | |
} |
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 CodeGolf.NatoTranslatorTest Extends %UnitTest.TestCase | |
{ | |
/// Should return a correctly translated string | |
Method TestUsingHardCodedStrings() | |
{ | |
Do $$$AssertEquals(##class(CodeGolf.NatoTranslator).ToNato("If you can read"), "India Foxtrot Yankee Oscar Uniform Charlie Alfa November Romeo Echo Alfa Delta") | |
Do $$$AssertEquals(##class(CodeGolf.NatoTranslator).ToNato("Did not see that coming"), "Delta India Delta November Oscar Tango Sierra Echo Echo Tango Hotel Alfa Tango Charlie Oscar Mike India November Golf") | |
Do $$$AssertEquals(##class(CodeGolf.NatoTranslator).ToNato("go for it!"), "Golf Oscar Foxtrot Oscar Romeo India Tango !") | |
} | |
/// Should return a correctly translated string | |
Method TestUsingRandomStrings() | |
{ | |
Set arr = $ListBuild("Alfa","November","Bravo","Oscar","Charlie","Papa","Delta","Quebec","Echo","Romeo", | |
"Foxtrot","Sierra","Golf","Tango","Hotel","Uniform","India","Victor", "Juliett","Whiskey","Xray","Kilo", | |
"Lima","Yankee","Mike","Zulu","?",".","!") | |
Set randTests = $Random(10) + 1 | |
Set strIn = "" | |
Set strOut = "" | |
For k = 1:1:randTests { | |
Set rd = $RANDOM($ListLength(arr)) + 1 | |
Set $List(strin, * + 1) = $Extract($List(arr,rd),1,1) | |
Set $List(strout, * + 1) = $List(arr,rd) | |
} | |
Do $$$AssertEquals(##class(CodeGolf.NatoTranslator).ToNato($ListToString(strin,"")), $ListToString(strout," ")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment