Skip to content

Instantly share code, notes, and snippets.

@henryhamon
Created September 9, 2022 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henryhamon/49a742e193ba524db0b848013b16ceeb to your computer and use it in GitHub Desktop.
Save henryhamon/49a742e193ba524db0b848013b16ceeb to your computer and use it in GitHub Desktop.
Class codeGolf.Pyramid
{
ClassMethod Build(f As %Integer)
{
; Your code here
}
}
Class codeGolf.test.Pyramid Extends %UnitTest.TestCase
{
ClassMethod openDisplay(Output filename As %String)
{
Set dir=##class(%SYSTEM.Process).CurrentDirectory()
Set filename=dir_"temp.txt"
Open filename:("NRW"):5
USE filename
}
ClassMethod getResult(filename As %String, Output list As %ListOfDataTypes)
{
Set list = ##class(%ListOfDataTypes).%New()
Set file = ##class(%File).%New(filename)
Set sc = file.Open( "R" )
If $$$ISERR(sc) quit
While 'file.AtEnd {
Do list.Insert(file.ReadLine())
}
Do file.Close()
Do ##class(%File).Delete(filename)
}
Method TestSimple()
{
Do ..openDisplay(.filename)
Do ##class(codeGolf.Pyramid).Build(3)
CLOSE filename
Do ..getResult(filename, .result)
Do $$$AssertEquals(result.GetAt(1), " # ")
Do $$$AssertEquals(result.GetAt(3), "#####")
}
Method TestComplex()
{
Do ..openDisplay(.filename)
Do ##class(codeGolf.Pyramid).Build(40)
CLOSE filename
Do ..getResult(filename, .result)
Do $$$AssertEquals(result.GetAt(1), " # ")
Do $$$AssertEquals(result.GetAt(23), " ############################################# ")
Do $$$AssertEquals(result.GetAt(40), "###############################################################################")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment