Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "log"
- )
- type Point struct {
- x float64
- y float64
- }
- func Point_new(x float64, y float64) *Point {
- p := new(Point)
- p.x = x
- p.y = y
- return p
- }
- func Point_get_x(p *Point) float64 {
- return p.x
- }
- func Point_get_y(p *Point) float64 {
- return p.y
- }
- func Point_set_x(p *Point, x float64) {
- p.x = x
- }
- func Point_set_y(p *Point, y float64) {
- p.y = y
- }
- func main() {
- p := Point_new(0, 0)
- if !(Point_get_x(p) == 0) {
- log.Fatal("Wrong value")
- }
- if !(Point_get_y(p) == 0) {
- log.Fatal("Wrong value")
- }
- Point_set_x(p, 3.0)
- Point_set_y(p, 4.0)
- if !(Point_get_x(p) == 3.0) {
- log.Fatal("Wrong value")
- }
- if !(Point_get_y(p) == 4.0) {
- log.Fatal("Wrong value")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement