From 86c1b1301359691dbebf04cd0e603942b7961eb4 Mon Sep 17 00:00:00 2001 From: Steven Degutis Date: Sat, 17 Mar 2012 12:47:22 -0500 Subject: [PATCH] types --- about_types.go | 13 +++++++++++++ setup_koans_test.go | 1 + 2 files changed, 14 insertions(+) create mode 100644 about_types.go diff --git a/about_types.go b/about_types.go new file mode 100644 index 0000000..a5a1131 --- /dev/null +++ b/about_types.go @@ -0,0 +1,13 @@ +package go_koans + +type coolNumber int + +func (cn coolNumber) double() int { + return int(cn) * 2 +} + +func aboutTypes() { + i := coolNumber(4) + assert(i == coolNumber(__int__)) // values can be converted between compatible types + assert(i.double() == __int__) // you can add methods on any type you define +} diff --git a/setup_koans_test.go b/setup_koans_test.go index 28b994c..6cdcde6 100644 --- a/setup_koans_test.go +++ b/setup_koans_test.go @@ -22,6 +22,7 @@ func TestKoans(t *testing.T) { aboutStrings() aboutArrays() aboutSlices() + aboutTypes() aboutControlFlow() aboutEnumeration() aboutAnonymousFunctions()