-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstructs.go
34 lines (27 loc) · 948 Bytes
/
structs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package workshop
// Student structs have a name and level
type Student struct {
name string
level string
}
// Stringer inserts a string in between name and level
func (student *Student) Stringer(str string) string {
return student.name + str + student.level
}
func structs() {
// Func expression that takes a pointer to Student and returns a string
student := func(student *Student) string {
return student.name + " is a " + student.level
}
actual := student(&Student{"Michael", "sophomore"})
expected := "Michael"
assert(actual == expected)
studentFinal := Student{name: "John Rambo", level: "Senior"}
actualStudentFinal := student(&studentFinal)
expectedStudentFinal := ""
assert(actualStudentFinal == expectedStudentFinal)
studentAlternative := Student{"Ada Lovelace", "Senior"}
actualAlternative := studentAlternative.Stringer(" was a ")
expectedAlternative := "__"
assert(actualAlternative == expectedAlternative)
}