finalizing the 4 basic files
This commit is contained in:
10
basics.go
10
basics.go
@@ -1,10 +0,0 @@
|
||||
package go_koans
|
||||
|
||||
func testNumbers() {
|
||||
//assert(__bool__ == true) // what is truth?
|
||||
//assert(__bool__ != false) // in it there is nothing false
|
||||
|
||||
//assert(__int__ == 1.0000000000000000000000000000000000000) // precision is in the eye of the beholder
|
||||
|
||||
//assert(true == 1)
|
||||
}
|
||||
9
numbers.go
Normal file
9
numbers.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package go_koans
|
||||
|
||||
func testNumbers() {
|
||||
assert(__bool__ == true) // what is truth?
|
||||
assert(__bool__ != false) // in it there is nothing false
|
||||
|
||||
var i int = __int__
|
||||
assert(i == 1.0000000000000000000000000000000000000) // precision is in the eye of the beholder
|
||||
}
|
||||
@@ -20,7 +20,7 @@ func TestKoans(t *testing.T) {
|
||||
//testNumbers()
|
||||
//testStrings()
|
||||
//testArrays()
|
||||
testSlices()
|
||||
//testSlices()
|
||||
|
||||
fmt.Printf("\n%c[32;1mYou won life. Good job.\n\n", 27)
|
||||
}
|
||||
|
||||
17
slices.go
17
slices.go
@@ -7,12 +7,17 @@ func testSlices() {
|
||||
assert(len(fruits) == __int__) // in nearly all respects
|
||||
|
||||
tasty_fruits := fruits[1:3] // we can even slice slices
|
||||
assert(tasty_fruits[0] == __string__) // slices of slices also share some data
|
||||
assert(tasty_fruits[1] == __string__) // but once again slightly askewed
|
||||
assert(tasty_fruits[0] == __string__) // slices of slices also share the underlying data
|
||||
|
||||
tasty_fruits[0] = "lemon"
|
||||
pregnancy_slots := []string{"baby", "baby", "lemon"}
|
||||
assert(cap(pregnancy_slots) == __int__) // the capacity is initially the length
|
||||
|
||||
assert(fruits[0] == __string__) // but once again
|
||||
assert(fruits[1] == __string__) // some things have changed
|
||||
assert(fruits[2] == __string__) // since our data is not our own
|
||||
pregnancy_slots = append(pregnancy_slots, "baby!")
|
||||
assert(len(pregnancy_slots) == __int__) // slices can be extended with append(), much like realloc in C
|
||||
assert(cap(pregnancy_slots) == __int__) // but with better optimizations
|
||||
|
||||
pregnancy_slots = append(pregnancy_slots, "another baby!?", "yet another, oh dear!", "they must be Catholic")
|
||||
|
||||
assert(len(pregnancy_slots) == __int__) // append() can take N arguments to append to the slice
|
||||
assert(cap(pregnancy_slots) == __int__) // the capacity optimizations have a guessable algorithm
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user