PageRenderTime 30ms CodeModel.GetById 10ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/rlglue/tests/test_1_experiment.go

https://code.google.com/p/go-glue/
Go | 123 lines | 121 code | 2 blank | 0 comment | 80 complexity | 79fe41995f68b608922226d70cc7b3a7 MD5 | raw file
  1package main
  2
  3import (
  4	"os"
  5	"fmt"
  6	"go-glue.googlecode.com/hg/rlglue"
  7)
  8
  9func main() {
 10	var err os.Error
 11	defer func() {
 12		if err != nil {
 13			panic(err)
 14		}
 15	}()
 16	gt := &GlueTester{"test_1", 0, 0}
 17	ex := new(rlglue.Experiment)
 18	if err = ex.AutoConnect(); err != nil {
 19		return
 20	}
 21	if _, err = ex.Init(); err != nil {
 22		return
 23	}
 24	if _, _, err = ex.Start(); err != nil {
 25		return
 26	}
 27	var obs rlglue.Observation
 28	var r float64
 29	var t bool
 30	var reply string
 31	if obs, _, r, t, err = ex.Step(); err != nil {
 32		return
 33	}
 34	reply, err = ex.EnvironmentMessage("one")
 35	gt.check("one|1.|one" != reply)
 36	reply, err = ex.AgentMessage("one")
 37	gt.check("one|1.|one" != reply)
 38	gt.check(t != false)
 39	gt.check(r != 1.0)
 40	gt.check(len(obs.Ints()) != 1)
 41	gt.check(len(obs.Doubles()) != 0)
 42	gt.check(len(obs.Chars()) != 0)
 43	gt.check(obs.Ints()[0] != 0)
 44	if obs, _, r, t, err = ex.Step(); err != nil {
 45		return
 46	}
 47	reply, err = ex.EnvironmentMessage("two")
 48	gt.check("two|2.2.|two" != reply)
 49	reply, err = ex.AgentMessage("two")
 50	gt.check("two|2.2.|two" != reply)
 51	gt.check(t != false)
 52	gt.check(r != 1.0)
 53	gt.check(len(obs.Ints()) != 1)
 54	gt.check(len(obs.Doubles()) != 0)
 55	gt.check(len(obs.Chars()) != 0)
 56	gt.check(obs.Ints()[0] != 1)
 57	if obs, _, r, t, err = ex.Step(); err != nil {
 58		return
 59	}
 60	reply, err = ex.EnvironmentMessage("three")
 61	gt.check("three||three" != reply)
 62	reply, err = ex.AgentMessage("three")
 63	gt.check("three||three" != reply)
 64	gt.check(t != false)
 65	gt.check(r != 1.0)
 66	gt.check(len(obs.Ints()) != 1)
 67	gt.check(len(obs.Doubles()) != 0)
 68	gt.check(len(obs.Chars()) != 0)
 69	gt.check(obs.Ints()[0] != 2)
 70	if obs, _, r, t, err = ex.Step(); err != nil {
 71		return
 72	}
 73	reply, err = ex.EnvironmentMessage("four")
 74	gt.check("four|4.|four" != reply)
 75	reply, err = ex.AgentMessage("four")
 76	gt.check("four|4.|four" != reply)
 77	gt.check(t != false)
 78	gt.check(r != 1.0)
 79	gt.check(len(obs.Ints()) != 1)
 80	gt.check(len(obs.Doubles()) != 0)
 81	gt.check(len(obs.Chars()) != 0)
 82	gt.check(obs.Ints()[0] != 3)
 83	if obs, _, r, t, err = ex.Step(); err != nil {
 84		return
 85	}
 86	reply, err = ex.EnvironmentMessage("five")
 87	gt.check("five|5.5.|five" != reply)
 88	reply, err = ex.AgentMessage("five")
 89	gt.check("five|4.|five" != reply)
 90	gt.check(t == false)
 91	gt.check(r != 1.0)
 92	if obs, _, r, t, err = ex.Step(); err != nil {
 93		return
 94	}
 95	gt.check(t != false)
 96	gt.check(r != -2.0)
 97	gt.check(len(obs.Ints()) != 5)
 98	gt.check(len(obs.Doubles()) != 5)
 99	gt.check(len(obs.Chars()) != 5)
100	gt.check(obs.Ints()[0] != 173)
101	gt.check(obs.Ints()[1] != -173)
102	gt.check(obs.Ints()[2] != 2147483647)
103	gt.check(obs.Ints()[3] != 0)
104	gt.check(obs.Ints()[4] != -2147483648)
105	gt.check(obs.Doubles()[0] != 0.0078125)
106	gt.check(obs.Doubles()[1] != -0.0078125)
107	gt.check(obs.Doubles()[2] != 0.0)
108	gt.check(obs.Doubles()[3] != 0.0078125e150)
109	gt.check(obs.Doubles()[4] != -0.0078125e150)
110	gt.check(obs.Chars()[0] != 'g')
111	gt.check(obs.Chars()[1] != 'F')
112	gt.check(obs.Chars()[2] != '?')
113	gt.check(obs.Chars()[3] != ' ')
114	gt.check(obs.Chars()[4] != '&')
115	if err = ex.Cleanup(); err != nil {
116		return
117	}
118	if err = ex.Close(); err != nil {
119		return
120	}
121	fmt.Printf("%v\n", gt)
122	os.Exit(gt.failCount)
123}