當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Context.Assume方法代碼示例

本文整理匯總了Golang中github.com/orfjackal/gospec/src/gospec.Context.Assume方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Assume方法的具體用法?Golang Context.Assume怎麽用?Golang Context.Assume使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/orfjackal/gospec/src/gospec.Context的用法示例。


在下文中一共展示了Context.Assume方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: MultiValueReturnSpec

func MultiValueReturnSpec(c gospec.Context) {
	c.Specify("Functions with zero or more than one return values work.", func() {
		context := polish.MakeContext()
		polish.AddIntMathContext(context)
		rev3 := func(a, b, c int) (int, int, int) {
			return c, b, a
		}
		context.AddFunc("rev3", rev3)
		rev5 := func(a, b, c, d, e int) (int, int, int, int, int) {
			return e, d, c, b, a
		}
		context.AddFunc("rev5", rev5)

		res, err := context.Eval("- - - - rev5 rev3 1 2 rev3 4 5 6")
		c.Assume(len(res), Equals, 1)
		c.Assume(err, Equals, nil)
		// - - - - rev5 rev3 1 2 rev3 4 5 6
		// - - - - rev5 rev3 1 2 6 5 4
		// - - - - rev5 6 2 1 5 4
		// - - - - 4 5 1 2 6
		// - - - -1 1 2 6
		// - - -2 2 6
		// - -4 6
		// -10
		c.Expect(int(res[0].Int()), Equals, -10)
	})
}
開發者ID:runningwild,項目名稱:polish,代碼行數:27,代碼來源:polish_test.go

示例2: ActionSpec

func ActionSpec(c gospec.Context) {
	game.RegisterActions()
	c.Specify("Actions are loaded properly.", func() {
		basic := game.MakeAction("Basic Test")
		_, ok := basic.(*actions.BasicAttack)
		c.Expect(ok, Equals, true)
	})

	c.Specify("Actions can be gobbed without loss of type.", func() {
		buf := bytes.NewBuffer(nil)
		enc := gob.NewEncoder(buf)

		var as []game.Action
		as = append(as, game.MakeAction("Move Test"))
		as = append(as, game.MakeAction("Basic Test"))

		err := enc.Encode(as)
		c.Assume(err, Equals, nil)

		dec := gob.NewDecoder(buf)
		var as2 []game.Action
		err = dec.Decode(&as2)
		c.Assume(err, Equals, nil)

		_, ok := as2[0].(*actions.Move)
		c.Expect(ok, Equals, true)

		_, ok = as2[1].(*actions.BasicAttack)
		c.Expect(ok, Equals, true)

	})
}
開發者ID:genbattle,項目名稱:haunts,代碼行數:32,代碼來源:action_test.go

示例3: ParsingSpec

func ParsingSpec(c gospec.Context) {
	c.Specify("Whitespace is parsed properly.", func() {
		context := polish.MakeContext()
		polish.AddIntMathContext(context)
		res, err := context.Eval("    +           1                      3")
		c.Assume(len(res), Equals, 1)
		c.Assume(err, Equals, nil)
		c.Expect(int(res[0].Int()), Equals, 4)
	})
}
開發者ID:runningwild,項目名稱:polish,代碼行數:10,代碼來源:polish_test.go

示例4: ErrorSpec

func ErrorSpec(c gospec.Context) {
	c.Specify("Type-mismatch panics are caught and returned as errors.", func() {
		context := polish.MakeContext()
		polish.AddIntMathContext(context)
		_, err := context.Eval("+ 1.0 2.0")
		c.Assume(err.Error(), Not(Equals), nil)
	})
	c.Specify("Panics from inside functions are caught and returned as errors.", func() {
		context := polish.MakeContext()
		context.AddFunc("panic", func() { panic("rawr") })
		_, err := context.Eval("panic")
		c.Assume(err.Error(), Not(Equals), nil)
	})
}
開發者ID:runningwild,項目名稱:polish,代碼行數:14,代碼來源:polish_test.go

示例5: TermSpec

func TermSpec(c gospec.Context) {
	g, err := yed.ParseFromFile("state.xgml")
	c.Assume(err, Equals, nil)
	aig := ai.NewGraph()
	aig.Graph = &g.Graph
	aig.Context = polish.MakeContext()
	polish.AddIntMathContext(aig.Context)
	polish.AddIntMathContext(aig.Context)
	c.Specify("Calling AiGraph.Term() will terminate evaluation early.", func() {
		var nearest int = 7
		nearest_func := func() int {
			return nearest
		}

		dist := 0
		term := true
		dist_func := func() int {
			if nearest == 6 && term {
				aig.Term() <- nil
			}
			return dist
		}

		attacks := 0
		attack_func := func() int {
			attacks++
			return 0
		}

		aig.Context.AddFunc("dist", dist_func)
		aig.Context.AddFunc("nearest", nearest_func)
		aig.Context.AddFunc("move", func() int { nearest--; return 0 })
		aig.Context.AddFunc("wait", func() int { return 0 })
		aig.Context.AddFunc("attack", attack_func)
		aig.Eval(2, func() bool { return true })

		c.Expect(attacks, Equals, 0)
		c.Expect(nearest, Equals, 6)

		term = false
		aig.Eval(2, func() bool { return true })
		c.Expect(nearest, Equals, 4)
	})
}
開發者ID:losinggeneration,項目名稱:glop,代碼行數:44,代碼來源:ai_test.go

示例6: NumRemainingValuesSpec

func NumRemainingValuesSpec(c gospec.Context) {
	c.Specify("Can handle any number of terms remaining after evaluation.", func() {
		context := polish.MakeContext()
		context.AddFunc("makeZero", func() {})
		context.AddFunc("makeTwo", func() (int, int) { return 1, 2 })
		res, err := context.Eval("makeTwo")
		c.Assume(len(res), Equals, 2)
		c.Assume(err, Equals, nil)
		res, err = context.Eval("makeZero")
		c.Assume(len(res), Equals, 0)
		c.Assume(err, Equals, nil)
	})
}
開發者ID:runningwild,項目名稱:polish,代碼行數:13,代碼來源:polish_test.go

示例7: ChunkSpec

func ChunkSpec(c gospec.Context) {
	g, err := yed.ParseFromFile("state.xgml")
	c.Assume(err, Equals, nil)
	aig := ai.NewGraph()
	aig.Graph = &g.Graph
	aig.Context = polish.MakeContext()
	polish.AddIntMathContext(aig.Context)
	polish.AddIntMathContext(aig.Context)
	c.Specify("cont() returning false will terminate evaluation early.", func() {
		var nearest int = 7
		nearest_func := func() int {
			return nearest
		}

		dist := 0
		term := true
		dist_func := func() int {
			if nearest == 6 && term {
				aig.Term() <- nil
			}
			return dist
		}

		attacks := 0
		attack_func := func() int {
			attacks++
			return 0
		}

		aig.Context.AddFunc("dist", dist_func)
		aig.Context.AddFunc("nearest", nearest_func)
		aig.Context.AddFunc("move", func() int { nearest--; return 0 })
		aig.Context.AddFunc("wait", func() int { return 0 })
		aig.Context.AddFunc("attack", attack_func)
		_, err := aig.Eval(4, func() bool { return false })
		// Only have time for 1 move before we terminate early
		c.Expect(err, Equals, nil)
		c.Expect(nearest, Equals, 6)
	})
}
開發者ID:losinggeneration,項目名稱:glop,代碼行數:40,代碼來源:ai_test.go

示例8: Float64ContextSpec

func Float64ContextSpec(c gospec.Context) {
	c.Specify("Float64 context works properly.", func() {
		context := polish.MakeContext()
		polish.AddFloat64MathContext(context)
		v1 := math.E * math.Pi * math.Exp(1.23456-math.Log10(77))
		res, err := context.Eval("* e * pi ^ e - 1.23456 log10 77.0")
		c.Assume(len(res), Equals, 1)
		c.Assume(err, Equals, nil)
		c.Expect(res[0].Float(), IsWithin(1e-9), v1)
		res, err = context.Eval("< e pi")
		c.Assume(len(res), Equals, 1)
		c.Assume(err, Equals, nil)
		c.Expect(res[0].Bool(), Equals, true)
	})
}
開發者ID:runningwild,項目名稱:polish,代碼行數:15,代碼來源:polish_test.go

示例9: AiSpec

func AiSpec(c gospec.Context) {
	c.Specify("Load a simple .xgml file.", func() {
		g, err := yed.ParseFromFile("state.xgml")
		c.Assume(err, Equals, nil)
		aig := ai.NewGraph()
		aig.Graph = &g.Graph
		aig.Context = polish.MakeContext()
		polish.AddIntMathContext(aig.Context)

		dist := 0
		dist_func := func() int {
			return dist
		}

		var nearest int = 7
		nearest_func := func() int {
			return nearest
		}

		attacks := 0
		attack_func := func() int {
			attacks++
			return 0
		}

		aig.Context.AddFunc("dist", dist_func)
		aig.Context.AddFunc("nearest", nearest_func)
		aig.Context.AddFunc("move", func() int { nearest--; return 0 })
		aig.Context.AddFunc("wait", func() int { return 0 })
		aig.Context.AddFunc("attack", attack_func)
		aig.Eval(2, func() bool { return true })

		c.Expect(attacks, Equals, 0)
		c.Expect(nearest, Equals, 4)
	})
}
開發者ID:losinggeneration,項目名稱:glop,代碼行數:36,代碼來源:ai_test.go

示例10: ParseOrderSpec

func ParseOrderSpec(c gospec.Context) {
	c.Specify("Parse order can be changed.", func() {
		context := polish.MakeContext()
		polish.AddFloat64MathContext(context)
		context.SetParseOrder(polish.Float) // Only parse as floats
		res, err := context.Eval("    +           1                      3")
		c.Assume(len(res), Equals, 1)
		c.Assume(err, Equals, nil)
		c.Expect(res[0].Float(), Equals, 4.0)

		context = polish.MakeContext()
		polish.AddIntMathContext(context)
		context.SetParseOrder(polish.Float) // Only parse as floats
		res, err = context.Eval("    +           1                      3")
		c.Assume(len(res), Equals, 0)
		c.Assume(err, Not(Equals), nil)
	})
}
開發者ID:runningwild,項目名稱:polish,代碼行數:18,代碼來源:polish_test.go

示例11: UnorderedTypeRegistrySpec

func UnorderedTypeRegistrySpec(c gospec.Context) {
	c.Specify("Test that the coder can decode packets out of order.", func() {
		var tr core.TypeRegistry
		tr.Register(encodable1{})
		tr.Register(encodable2{})
		tr.Complete()

		v1 := encodable1{1, 2}
		v2 := encodable2{3}
		v3 := encodable2{4}
		v4 := encodable1{5, 6}

		b1 := bytes.NewBuffer(nil)
		err := tr.Encode(v1, b1)
		c.Assume(err, gospec.Equals, error(nil))

		b2 := bytes.NewBuffer(nil)
		err = tr.Encode(v2, b2)
		c.Assume(err, gospec.Equals, error(nil))

		b3 := bytes.NewBuffer(nil)
		err = tr.Encode(v3, b3)
		c.Assume(err, gospec.Equals, error(nil))

		b4 := bytes.NewBuffer(nil)
		err = tr.Encode(v4, b4)
		c.Assume(err, gospec.Equals, error(nil))

		buf := bytes.NewBuffer(nil)
		buf.Write(b1.Bytes())
		buf.Write(b3.Bytes())
		buf.Write(b4.Bytes())
		buf.Write(b2.Bytes())

		d1, err := tr.Decode(buf)
		c.Assume(err, gospec.Equals, error(nil))
		d3, err := tr.Decode(buf)
		c.Assume(err, gospec.Equals, error(nil))
		d4, err := tr.Decode(buf)
		c.Assume(err, gospec.Equals, error(nil))
		d2, err := tr.Decode(buf)
		c.Assume(err, gospec.Equals, error(nil))

		c.Expect(d1, gospec.Equals, v1)
		c.Expect(d2, gospec.Equals, v2)
		c.Expect(d3, gospec.Equals, v3)
		c.Expect(d4, gospec.Equals, v4)
	})
}
開發者ID:runningwild,項目名稱:sgf,代碼行數:49,代碼來源:encoder_test.go

示例12: BasicTypeRegistrySpec

func BasicTypeRegistrySpec(c gospec.Context) {
	c.Specify("Test the coder.", func() {
		var tr core.TypeRegistry
		tr.Register(encodable1{})
		tr.Register(encodable2{})
		tr.Register(encodable3([]byte{}))
		tr.Register(encodable4{})
		tr.Register(encodable5{})
		tr.Register(encodable7{})
		tr.Register(encodable8{})
		tr.Register(encodable9{})
		tr.Register(encodable10{})
		tr.Register(encodable11{})
		tr.Register(encodable12{})
		tr.Register(encodable13{})
		tr.Register(encodable14{})
		tr.Complete()

		c.Specify("Test that encoder handles int32.", func() {
			e1 := encodable1{1, 2}
			buf := bytes.NewBuffer(nil)
			err := tr.Encode(e1, buf)
			c.Assume(err, gospec.Equals, error(nil))
			dec1, err := tr.Decode(buf)
			c.Assume(err, gospec.Equals, error(nil))
			d1, ok := dec1.(encodable1)
			c.Assume(ok, gospec.Equals, true)
			c.Expect(dec1.(ider).id(), gospec.Equals, 1)
			c.Expect(d1, gospec.Equals, e1)
		})

		c.Specify("Test that encoder handles byte.", func() {
			e2 := encodable2{14}
			buf := bytes.NewBuffer(nil)
			err := tr.Encode(e2, buf)
			c.Assume(err, gospec.Equals, error(nil))
			dec2, err := tr.Decode(buf)
			c.Assume(err, gospec.Equals, error(nil))
			d2, ok := dec2.(encodable2)
			c.Assume(ok, gospec.Equals, true)
			c.Expect(dec2.(ider).id(), gospec.Equals, 2)
			c.Expect(d2, gospec.Equals, e2)
		})

		c.Specify("Test that encoder handles string.", func() {
			e3 := encodable3("fudgeball")
			buf := bytes.NewBuffer(nil)
			err := tr.Encode(e3, buf)
			c.Assume(err, gospec.Equals, error(nil))
			dec3, err := tr.Decode(buf)
			c.Assume(err, gospec.Equals, error(nil))
			d3, ok := dec3.(encodable3)
			c.Assume(ok, gospec.Equals, true)
			c.Expect(dec3.(ider).id(), gospec.Equals, 3)
			c.Expect(string(d3), gospec.Equals, string(e3))
		})

		c.Specify("Test that encoder handles composite structs.", func() {
			e4 := encodable4{
				A: e4sub1{
					B: 10,
					C: 20,
					D: e4sub2{
						E: "foo",
						F: "bar",
					},
				},
				G: 12345,
			}
			buf := bytes.NewBuffer(nil)
			err := tr.Encode(e4, buf)
			c.Assume(err, gospec.Equals, error(nil))
			dec4, err := tr.Decode(buf)
			c.Assume(err, gospec.Equals, error(nil))
			d4, ok := dec4.(encodable4)
			c.Assume(ok, gospec.Equals, true)
			c.Expect(dec4.(ider).id(), gospec.Equals, 4)
			c.Expect(d4, gospec.Equals, e4)
		})

		c.Specify("Test that encoder handles []byte.", func() {
			e5 := encodable5{
				A: []byte("Monkeyball"),
			}
			buf := bytes.NewBuffer(nil)
			err := tr.Encode(e5, buf)
			c.Assume(err, gospec.Equals, error(nil))
			dec5, err := tr.Decode(buf)
			c.Assume(err, gospec.Equals, error(nil))
			d5, ok := dec5.(encodable5)
			c.Assume(ok, gospec.Equals, true)
			c.Expect(dec5.(ider).id(), gospec.Equals, 5)
			c.Expect(string(d5.A), gospec.Equals, string(e5.A))
		})

		c.Specify("Test that encoder handles int and uint.", func() {
			e7 := encodable7{
				A: 1,
				B: 2,
			}
//.........這裏部分代碼省略.........
開發者ID:runningwild,項目名稱:sgf,代碼行數:101,代碼來源:encoder_test.go

示例13: EventSpec

func EventSpec(c gospec.Context) {
	input := gin.Make()
	AB_binding := input.MakeBinding('a', []gin.KeyId{'b'}, []bool{true})
	AB := input.BindDerivedKey("AB", AB_binding)
	CD_binding := input.MakeBinding('c', []gin.KeyId{'d'}, []bool{true})
	CD := input.BindDerivedKey("CD", CD_binding)
	AB_CD_binding := input.MakeBinding(AB.Id(), []gin.KeyId{CD.Id()}, []bool{true})
	_ = input.BindDerivedKey("AB CD", AB_CD_binding)
	events := make([]gin.OsEvent, 0)

	check := func(lengths ...int) {
		groups := input.Think(10, false, events)
		c.Assume(len(groups), Equals, len(lengths))
		for i, length := range lengths {
			c.Assume(len(groups[i].Events), Equals, length)
		}
	}

	c.Specify("Testing order 'abcd'.", func() {
		injectEvent(&events, 'a', 1, 1)
		injectEvent(&events, 'b', 1, 2)
		injectEvent(&events, 'c', 1, 3)
		injectEvent(&events, 'd', 1, 4)
		check(1, 1, 1, 1)
	})

	c.Specify("Testing order 'dbca'.", func() {
		injectEvent(&events, 'd', 1, 1)
		injectEvent(&events, 'b', 1, 2)
		injectEvent(&events, 'c', 1, 3)
		injectEvent(&events, 'a', 1, 4)
		check(1, 1, 2, 3)
	})

	c.Specify("Testing order 'dcba'.", func() {
		injectEvent(&events, 'd', 1, 1)
		injectEvent(&events, 'c', 1, 2)
		injectEvent(&events, 'b', 1, 3)
		injectEvent(&events, 'a', 1, 4)
		check(1, 2, 1, 3)
	})

	c.Specify("Testing order 'bcda'.", func() {
		injectEvent(&events, 'b', 1, 1)
		injectEvent(&events, 'c', 1, 2)
		injectEvent(&events, 'd', 1, 3)
		injectEvent(&events, 'a', 1, 4)
		check(1, 1, 1, 2)
	})

	// This test also checks that a derived key stays down until the primary key is released
	// CD is used here after D is released to trigger AB_CD
	c.Specify("Testing order 'dcbDad'.", func() {
		injectEvent(&events, 'd', 1, 1)
		injectEvent(&events, 'c', 1, 2)
		injectEvent(&events, 'b', 1, 3)
		injectEvent(&events, 'd', 0, 4)
		injectEvent(&events, 'a', 1, 5)
		injectEvent(&events, 'd', 1, 6)
		check(1, 2, 1, 1, 3, 1)
	})
}
開發者ID:losinggeneration,項目名稱:glop,代碼行數:62,代碼來源:input_test.go

示例14: BundlerSpec

func BundlerSpec(c gospec.Context) {
	c.Specify("Basic Bundler functionality.", func() {
		var params core.EngineParams
		params.Id = 1234
		params.Delay = 2
		params.Frame_ms = 5
		params.Max_frames = 25
		bundles := make(chan core.FrameBundle)
		local_event := make(chan core.Event)
		var bundler core.Bundler
		bundler.Params = params
		bundler.Local_bundles = bundles
		bundler.Local_event = local_event
		bundler.Time_delta = nil
		ticker := &core.FakeTicker{}
		bundler.Ticker = ticker
		bundler.Start()
		c.Expect(1, Equals, 1)
		go func() {
			for i := 0; i < 10; i++ {
				if i%2 == 0 {
					local_event <- &EventA{i}
					local_event <- &EventB{fmt.Sprintf("%d", i)}
				} else {
					local_event <- &EventB{fmt.Sprintf("%d", i)}
					local_event <- &EventA{i}
				}
				// Advance two frames, so we will have two events per every other
				// frame.
				ticker.Inc(10)
			}
			bundler.Shutdown()
		}()
		var frame core.StateFrame = 0
		for bundle := range bundles {
			c.Expect(bundle.Frame, Equals, frame)
			events, ok := bundle.Bundle[params.Id]
			c.Assume(ok, Equals, true)
			c.Expect(len(events.Engine), Equals, 0)
			if ok {
				if frame%2 == 0 {
					c.Expect(len(events.Game), Equals, 2)
				} else {
					c.Expect(len(events.Game), Equals, 0)
				}
			}
			if frame%2 == 0 {
				c.Expect(len(bundle.Bundle), Equals, 1)
				c.Specify("checking bundle values", func() {
					index_a := 0
					if frame%4 != 0 {
						index_a = 1
					}
					ea, aok := events.Game[index_a].(*EventA)
					eb, bok := events.Game[(index_a+1)%2].(*EventB)
					c.Assume(aok, Equals, true)
					c.Assume(bok, Equals, true)
					c.Specify("checking event data", func() {
						c.Expect(ea.Data, Equals, int(frame/2))
						c.Expect(eb.Data, Equals, fmt.Sprintf("%d", frame/2))
					})
				})
			}
			frame++
		}
	})
}
開發者ID:runningwild,項目名稱:pnf,代碼行數:67,代碼來源:bundler_test.go

示例15: IntOperatorSpec

func IntOperatorSpec(c gospec.Context) {
	c.Specify("All standard int operators parse.", func() {
		context := polish.MakeContext()
		polish.AddIntMathContext(context)
		c.Specify("+ works", func() {
			_, err := context.Eval("+ 1 2")
			c.Assume(err, Equals, nil)
		})
		c.Specify("- works", func() {
			_, err := context.Eval("- 1 2")
			c.Assume(err, Equals, nil)
		})
		c.Specify("* works", func() {
			_, err := context.Eval("* 1 2")
			c.Assume(err, Equals, nil)
		})
		c.Specify("/ works", func() {
			_, err := context.Eval("/ 1 2")
			c.Assume(err, Equals, nil)
		})
		c.Specify("< works", func() {
			_, err := context.Eval("< 1 2")
			c.Assume(err, Equals, nil)
		})
		c.Specify("<= works", func() {
			_, err := context.Eval("<= 1 2")
			c.Assume(err, Equals, nil)
		})
		c.Specify("> works", func() {
			_, err := context.Eval("> 1 2")
			c.Assume(err, Equals, nil)
		})
		c.Specify(">= works", func() {
			_, err := context.Eval(">= 1 2")
			c.Assume(err, Equals, nil)
		})
		c.Specify("== works", func() {
			_, err := context.Eval("== 1 2")
			c.Assume(err, Equals, nil)
		})
	})
}
開發者ID:runningwild,項目名稱:polish,代碼行數:42,代碼來源:polish_test.go


注:本文中的github.com/orfjackal/gospec/src/gospec.Context.Assume方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。