structs
This commit is contained in:
24
about_structs.go
Normal file
24
about_structs.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package go_koans
|
||||||
|
|
||||||
|
func testStructs() {
|
||||||
|
var bob struct {
|
||||||
|
name string
|
||||||
|
age int
|
||||||
|
}
|
||||||
|
bob.name = "bob"
|
||||||
|
bob.age = 30
|
||||||
|
|
||||||
|
assert(bob.name == __string__) // structs are collections of named variables
|
||||||
|
assert(bob.age == __int__) // each field has both setter and getter behavior
|
||||||
|
|
||||||
|
type person struct {
|
||||||
|
name string
|
||||||
|
age int
|
||||||
|
}
|
||||||
|
|
||||||
|
var john person
|
||||||
|
john.name = "bob"
|
||||||
|
john.age = __int__
|
||||||
|
|
||||||
|
assert(bob == john) // assuredly, bob is certainly not john.. yet
|
||||||
|
}
|
||||||
@@ -28,10 +28,10 @@ func TestKoans(t *testing.T) {
|
|||||||
//testFiles()
|
//testFiles()
|
||||||
//testInterfaces()
|
//testInterfaces()
|
||||||
//testMaps()
|
//testMaps()
|
||||||
testPointers()
|
//testPointers()
|
||||||
|
testStructs()
|
||||||
|
|
||||||
// TODO: ie, gameplan
|
// TODO: ie, gameplan
|
||||||
//testStructs()
|
|
||||||
//testAllocation()
|
//testAllocation()
|
||||||
//testGoroutines()
|
//testGoroutines()
|
||||||
//testChannels()
|
//testChannels()
|
||||||
|
|||||||
Reference in New Issue
Block a user