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


Golang Context.Expect方法代碼示例

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


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

示例1: FFTR2CSpec

func FFTR2CSpec(c gospec.Context) {
	signal := make([]float64, 16)
	F_signal := make([]complex128, 9)

	for i := range signal {
		signal[i] = math.Sin(float64(i) / float64(len(signal)) * math.Pi * 2)
	}
	forward := PlanDftR2C1d(signal, F_signal, Estimate)
	forward.Execute()
	c.Specify("Running a R2C transform doesn't destroy the input.", func() {
		for i := range signal {
			c.Expect(signal[i], gospec.Equals, math.Sin(float64(i)/float64(len(signal))*math.Pi*2))
		}
	})

	c.Specify("Forward 1d Real to Complex FFT  works properly.", func() {
		c.Expect(real(F_signal[0]), gospec.IsWithin(1e-9), 0.0)
		c.Expect(imag(F_signal[0]), gospec.IsWithin(1e-9), 0.0)
		c.Expect(real(F_signal[1]), gospec.IsWithin(1e-9), 0.0)
		c.Expect(imag(F_signal[1]), gospec.IsWithin(1e-9), -float64(len(signal))/2)
		for i := 2; i < len(F_signal)-1; i++ {
			c.Expect(real(F_signal[i]), gospec.IsWithin(1e-9), 0.0)
			c.Expect(imag(F_signal[i]), gospec.IsWithin(1e-9), 0.0)
		}
	})
}
開發者ID:jtc25,項目名稱:go-fftw,代碼行數:26,代碼來源:fftw_test.go

示例2: CMWCRandSpec

func CMWCRandSpec(c gospec.Context) {
	c.Specify("CMWC32 conforms properly to math/rand.Rand interface.", func() {
		c1 := cmwc.MakeCmwc(3278470471, 4)
		c2 := cmwc.MakeCmwc(3278470471, 4)
		c1.Seed(1234)
		c2.Seed(4321)

		// Make sure that we don't generate numbers with the most significant
		// bit set
		for i := 0; i < 1000000; i++ {
			v1 := c1.Int63()
			c.Expect(v1 >= 0, Equals, true)
			if v1 < 0 {
				break
			}
			c2.Int63()
		}

		// Make sure that two generators with the same parameters, but in
		// different states, are in the exact same state when seeded with
		// the same seed.
		c1.Seed(0xabcdef12)
		c2.Seed(0xabcdef12)
		for i := 0; i < 10000; i++ {
			v1 := c1.Int63()
			v2 := c2.Int63()
			c.Expect(v1, Equals, v2)
			if v1 != v2 {
				break
			}
		}
	})
}
開發者ID:runningwild,項目名稱:cmwc,代碼行數:33,代碼來源:cmwc_test.go

示例3: InterfaceTypeRegistrySpec

func InterfaceTypeRegistrySpec(c gospec.Context) {
	c.Specify("Test that types containing interfaces are properly encoded.", func() {
		var tr core.TypeRegistry
		tr.Register(encodable6{})
		tr.Register(BarerImpl1{})
		tr.Register(BarerImpl2{})
		tr.Complete()

		v1 := encodable6{
			Interface: BarerImpl1{10, "foo"},
		}
		v2 := encodable6{
			Interface: BarerImpl2{3, 4},
		}

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

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

		c1, ok := d1.(encodable6)
		c.Assume(ok, gospec.Equals, true)
		c.Expect(c1.Interface.Bar(), gospec.Equals, "10:foo")
		c2, ok := d2.(encodable6)
		c.Assume(ok, gospec.Equals, true)
		c.Expect(c2.Interface.Bar(), gospec.Equals, "3:4")
	})
}
開發者ID:runningwild,項目名稱:sgf,代碼行數:34,代碼來源:encoder_test.go

示例4: StackSpec

func StackSpec(c gospec.Context) {
	stack := NewStack()

	c.Specify("An empty stack", func() {

		c.Specify("is empty", func() {
			c.Expect(stack.Empty(), IsTrue)
		})
		c.Specify("After a push, the stack is no longer empty", func() {
			stack.Push("a push")
			c.Expect(stack.Empty(), IsFalse)
		})
	})

	c.Specify("When objects have been pushed onto a stack", func() {
		stack.Push("pushed first")
		stack.Push("pushed last")

		c.Specify("the object pushed last is popped first", func() {
			poppedFirst := stack.Pop()
			c.Expect(poppedFirst, Equals, "pushed last")
		})
		c.Specify("the object pushed first is popped last", func() {
			stack.Pop()
			poppedLast := stack.Pop()
			c.Expect(poppedLast, Equals, "pushed first")
		})
		c.Specify("After popping all objects, the stack is empty", func() {
			stack.Pop()
			stack.Pop()
			c.Expect(stack.Empty(), IsTrue)
		})
	})
}
開發者ID:rafrombrc,項目名稱:gospec,代碼行數:34,代碼來源:stack_test.go

示例5: FFT1dSpec

func FFT1dSpec(c gospec.Context) {
	signal := Alloc1d(16)
	new_in := Alloc1d(16)
	new_out := Alloc1d(16)
	for i := range signal {
		signal[i] = complex(float32(i), float32(-i))
		new_in[i] = signal[i]
	}
	forward := PlanDft1d(signal, signal, Forward, Estimate)
	c.Specify("Creating a plan doesn't overwrite an existing array if fftw.Estimate is used.", func() {
		for i := range signal {
			c.Expect(signal[i], gospec.Equals, complex(float32(i), float32(-i)))
		}
	})

	// A simple real cosine should result in transform with two spikes, one at S[1] and one at S[-1]
	// The spikes should be real and have amplitude equal to len(S)/2 (because fftw doesn't normalize)
	for i := range signal {
		signal[i] = complex(float32(math.Cos(float64(i)/float64(len(signal))*math.Pi*2)), 0)
		new_in[i] = signal[i]
	}
	forward.Execute()
	c.Specify("Forward 1d FFT works properly.", func() {
		peakVerifier(signal, c)
	})

	// This should also be the case when using new arrays...
	forward.ExecuteNewArray(new_in, new_out)
	c.Specify("New array Forward 1d FFT works properly", func() {
		peakVerifier(new_out, c)
	})
}
開發者ID:juanmb,項目名稱:go-fftwf,代碼行數:32,代碼來源:fftw_test.go

示例6: CommandNSpec

func CommandNSpec(c gospec.Context) {
	c.Specify("Sample sprite loads correctly", func() {
		s, err := sprite.LoadSprite("test_sprite")
		c.Expect(err, Equals, nil)
		for i := 0; i < 2000; i++ {
			s.Think(50)
		}
		s.CommandN([]string{
			"turn_right",
			"turn_right",
			"turn_right",
			"turn_right",
			"turn_right",
			"turn_right",
			"turn_left",
			"turn_left",
			"turn_right",
			"turn_right",
			"turn_right",
			"turn_left",
			"turn_left"})
		s.Think(5000)
		c.Expect(s.Facing(), Equals, 1)
		for i := 0; i < 3000; i++ {
			s.Think(50)
		}
	})
}
開發者ID:runningwild,項目名稱:glop,代碼行數:28,代碼來源:sprite_test.go

示例7: LoadSpriteSpec

func LoadSpriteSpec(c gospec.Context) {
	c.Specify("Sample sprite loads correctly", func() {
		s, err := sprite.LoadSprite("test_sprite")
		c.Expect(err, Equals, nil)
		for i := 0; i < 2000; i++ {
			s.Think(50)
		}
		s.Command("defend")
		s.Command("undamaged")
		s.Command("defend")
		s.Command("undamaged")
		for i := 0; i < 3000; i++ {
			s.Think(50)
		}
		s.Command("turn_right")
		s.Command("turn_right")
		s.Command("turn_right")
		s.Command("turn_right")
		s.Command("turn_right")
		s.Command("turn_right")
		s.Command("turn_left")
		s.Command("turn_left")
		s.Command("turn_right")
		s.Command("turn_right")
		s.Command("turn_right")
		s.Command("turn_left")
		s.Command("turn_left")
		// s.Think(5000)
		for i := 0; i < 300; i++ {
			s.Think(50)
		}
		c.Expect(s.Facing(), Equals, 1)
	})
}
開發者ID:runningwild,項目名稱:glop,代碼行數:34,代碼來源:sprite_test.go

示例8: TopologicalSortSpec

func TopologicalSortSpec(c gospec.Context) {
	gr := NewDirectedMap()
	c.Specify("Single node graph", func() {
		gr.AddNode(VertexId(1))
		nodes, hasCycle := TopologicalSort(gr)
		c.Expect(hasCycle, IsFalse)
		c.Expect(nodes, ContainsExactly, Values(VertexId(1)))
	})

	c.Specify("Simple two nodes graph", func() {
		gr.AddArc(1, 2)
		nodes, hasCycle := TopologicalSort(gr)
		c.Expect(hasCycle, IsFalse)
		c.Expect(nodes, ContainsExactly, Values(VertexId(1), VertexId(2)))
	})

	c.Specify("Pseudo loops", func() {
		gr.AddArc(1, 2)
		gr.AddArc(2, 3)
		gr.AddArc(1, 4)
		gr.AddArc(4, 3)

		_, hasCycle := TopologicalSort(gr)
		c.Expect(hasCycle, IsFalse)
	})
}
開發者ID:tusj,項目名稱:go-graph,代碼行數:26,代碼來源:algorithms_test.go

示例9: PolySpec2

func PolySpec2(c gospec.Context) {
	p := linear.Poly{
		{-1, 0},
		{-3, 0},
		{0, 10},
		{3, 0},
		{1, 0},
		{2, 1},
		{-2, 1},
	}
	c.Specify("Check that exterior and interior segments of a polygon are correctly identified.", func() {
		visible_exterior := []linear.Seg2{
			linear.MakeSeg2(-1, 0, -3, 0),
			linear.MakeSeg2(2, 1, -2, 1),
			linear.MakeSeg2(3, 0, 1, 0),
		}
		visible_interior := []linear.Seg2{
			linear.MakeSeg2(2, 1, -2, 1),
			linear.MakeSeg2(-3, 0, 0, 10),
			linear.MakeSeg2(0, 10, 3, 0),
			linear.MakeSeg2(-1, 0, -3, 0),
			linear.MakeSeg2(3, 0, 1, 0),
		}
		c.Expect(p.VisibleExterior(linear.Vec2{0, -10}), ContainsExactly, visible_exterior)
		c.Expect(p.VisibleInterior(linear.Vec2{0, 5}), ContainsExactly, visible_interior)
	})
}
開發者ID:runningwild,項目名稱:linear,代碼行數:27,代碼來源:linear_test.go

示例10: 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

示例11: checkOrder

func checkOrder(c gospec.Context, a adag, order []int) {
	c.Expect(len(a), Equals, len(order))
	c.Specify("Ordering contains all vertices exactly once", func() {
		all := make(map[int]bool)
		for _, v := range order {
			all[v] = true
		}
		c.Expect(len(all), Equals, len(order))
		for i := 0; i < len(a); i++ {
			c.Expect(all[i], Equals, true)
		}
	})
	c.Specify("Successors of a vertex always occur later in the ordering", func() {
		for i := 0; i < len(order); i++ {
			all := a.AllSuccessors(order[i])
			for j := range order {
				if i == j {
					continue
				}
				succ, ok := all[order[j]]
				if j < i {
					c.Expect(!ok, Equals, true)
				} else {
					c.Expect(!ok || succ, Equals, true)
				}
			}
		}
	})
}
開發者ID:losinggeneration,項目名稱:glop,代碼行數:29,代碼來源:graph_test.go

示例12: ComplexOperationsSpec

func ComplexOperationsSpec(c gospec.Context) {
	c.Specify("Vec2.DistToLine() works.", func() {
		centers := []linear.Vec2{
			linear.Vec2{10, 12},
			linear.Vec2{1, -9},
			linear.Vec2{-100, -42},
			linear.Vec2{0, 1232},
		}
		radiuses := []float64{3, 10.232, 435, 1}
		thetas := []float64{0.001, 0.1, 1, 1.01, 0.034241, 0.789, 90, 179, 180}
		angles := []float64{1.01, 1.0, 1.11111, 930142}
		for _, center := range centers {
			for _, radius := range radiuses {
				for _, angle := range angles {
					for _, theta := range thetas {
						a := linear.Vec2{math.Cos(angle), math.Sin(angle)}
						b := linear.Vec2{math.Cos(angle + theta), math.Sin(angle + theta)}
						seg := linear.Seg2{a.Scale(radius).Add(center), b.Scale(radius).Add(center)}
						dist := center.DistToLine(seg)
						real_dist := radius * math.Cos(theta/2)
						if real_dist < 0 {
							real_dist = -real_dist
						}
						c.Expect(dist, IsWithin(1e-9), real_dist)
					}
				}
			}
		}
	})
}
開發者ID:runningwild,項目名稱:linear,代碼行數:30,代碼來源:linear_test.go

示例13: DecodePositionSpecs

// Helpers
func DecodePositionSpecs(c gospec.Context) {
	c.Specify("[Decode] Decodes GeoHash to PreciseLocation + Error", func() {
		value := Decode("ww8p1r4t8")

		c.Expect(value.Location.Latitude, gospec.Satisfies, value.Location.Latitude >= 37.83 && value.Location.Latitude <= (37.84))
		c.Expect(value.Location.Longitude, gospec.Satisfies, value.Location.Longitude >= 112.55 && value.Location.Longitude <= (112.56))
	})
}
開發者ID:RUNDSP,項目名稱:ggeohash,代碼行數:9,代碼來源:decode_position_test.go

示例14: FindPortSpecs

func FindPortSpecs(c gospec.Context) {
	c.Specify("[findPort] Finds an open port", func() {
		port, err := findPort()
		c.Expect(err, gospec.Equals, nil)
		c.Expect(port, gospec.Satisfies, port >= 1024)
	})

}
開發者ID:RUNDSP,項目名稱:dog_pool,代碼行數:8,代碼來源:find_port_test.go

示例15: AcceptanceSpec

func AcceptanceSpec(c gospec.Context) {

	c.Specify("When send structed data should return stracted data", func() {

		expectedData := &ResponseData{0, "3, 5, 7, 20"}
		actualData := &TaskData{0, PING, "3, 5, 7, 20"}

		var result = SendRequest(actualData)
		c.Expect(result.TaskId, Equals, expectedData.TaskId)
		c.Expect(result.ResultData, Equals, expectedData.ResultData)
	})

	/*c.Specify("When send unsorted strings data should return sorted strings data", func() {

				actualData := &TaskData{0, SORT, "7, 3, 20, 5"}
				expectedData := &TaskData{0, SORT, "3, 5, 7, 20"}

				var result = SendRequest(actualData)
				c.Expect(result.TaskData, Equals, expectedData.TaskData)
		})

		c.Specify("When send unsorted strings data processor should return sorted strings data", func() {
				actualData := &TaskData{0, SORT, "7, 3, 40, 5"}
				expectedData := &ResponseData{0, "3, 5, 7, 40"}

				requestChannel := make(chan domain.TaskData)
				responseChannel := make(chan domain.ResponseData)
				go server.TaskProcessor(requestChannel, responseChannel)
				requestChannel <-  *actualData

				var result = <- responseChannel
				c.Expect(result.ResultData, Equals, expectedData.ResultData)
				c.Expect(result.TaskId, Equals, expectedData.TaskId)

		})

		c.Specify("Test task processor with many tasks", func() {
				actualData := &TaskData{0, SORT, "7, 3, 40, 5"}
				expectedData := &ResponseData{0, "3, 5, 7, 40"}

				requestChannel := make(chan domain.TaskData, 100)
				responseChannel := make(chan domain.ResponseData, 100)
				go server.TaskProcessor(requestChannel, responseChannel)

				for i := 0; i < 10; i++ {
					requestChannel <-  *actualData
				}
				killPackage := &TaskData{0, KILL, "7, 3, 40, 5"}
				requestChannel <-  *killPackage

				for i := 0; i < 10; i++ {
	//				requestChannel <-  *actualData
					var result = <- responseChannel
					c.Expect(result.ResultData, Equals, expectedData.ResultData)
					c.Expect(result.TaskId, Equals, expectedData.TaskId)
				}
			})*/
}
開發者ID:eshepelyuk,項目名稱:CodingDojoCnUa,代碼行數:58,代碼來源:test_acceptance.go


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