PageRenderTime 15ms CodeModel.GetById 2ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/trunk/Examples/test-suite/go/member_pointer_runme.go

#
Go | 49 lines | 26 code | 16 blank | 7 comment | 2 complexity | d523db1260a574266728b85b71600e6e MD5 | raw file
 1// Example using pointers to member functions
 2
 3package main
 4
 5import "fmt"
 6import . "./member_pointer"
 7
 8func check(what string, expected float64, actual float64) {
 9	if expected != actual {
10		panic(fmt.Sprintf("Failed: %s Expected: %f Actual; %f", what, expected, actual))
11	}
12}
13
14func main() {
15	// Get the pointers
16
17	area_pt := Areapt()
18	perim_pt := Perimeterpt()
19
20	// Create some objects
21
22	s := NewSquare(10)
23
24	// Do some calculations
25
26	check("Square area ", 100.0, Do_op(s, area_pt))
27	check("Square perim", 40.0, Do_op(s, perim_pt))
28
29	_ = GetAreavar()
30	_ = GetPerimetervar()
31
32	// Try the variables
33	check("Square area ", 100.0, Do_op(s, GetAreavar()))
34	check("Square perim", 40.0, Do_op(s, GetPerimetervar()))
35
36	// Modify one of the variables
37	SetAreavar(perim_pt)
38
39	check("Square perimeter", 40.0, Do_op(s, GetAreavar()))
40
41	// Try the constants
42
43	_ = AREAPT
44	_ = PERIMPT
45	_ = NULLPT
46
47	check("Square area ", 100.0, Do_op(s, AREAPT))
48	check("Square perim", 40.0, Do_op(s, PERIMPT))
49}