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


Golang gospec.Context類代碼示例

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


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

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

示例2: Alloc3dSpec

func Alloc3dSpec(c gospec.Context) {
	d100x20x10 := Alloc3d(100, 20, 10)
	c.Specify("Allocates the appropriate memory for 3d arrays.", func() {
		c.Expect(len(d100x20x10), gospec.Equals, 100)
		for _, v := range d100x20x10 {
			c.Expect(len(v), gospec.Equals, 20)
			for _, v := range v {
				c.Expect(len(v), gospec.Equals, 10)
			}
		}
		counter := 0.0
		for i := range d100x20x10 {
			for j := range d100x20x10[i] {
				for k := range d100x20x10[i][j] {
					d100x20x10[i][j][k] = complex(counter, 0)
					counter += 1.0
				}
			}
		}
		counter = 0.0
		for i := range d100x20x10 {
			for j := range d100x20x10[i] {
				for k := range d100x20x10[i][j] {
					c.Expect(real(d100x20x10[i][j][k]), gospec.Equals, counter)
					counter += 1.0
				}
			}
		}
	})
}
開發者ID:jtc25,項目名稱:go-fftw,代碼行數:30,代碼來源:fftw_test.go

示例3: DecodeBoundBoxSpecs

// Helpers
func DecodeBoundBoxSpecs(c gospec.Context) {
	c.Specify("[DecodeBoundBox] Decodes GeoHash to DecodedBoundBox", func() {
		value := DecodeBoundBox("ww8p1r4t8")

		c.Expect(value.Min.Latitude, gospec.Equals, 37.83236503601074)
		c.Expect(value.Min.Longitude, gospec.Equals, 112.55836486816406)
		c.Expect(value.Max.Latitude, gospec.Equals, 37.83240795135498)
		c.Expect(value.Max.Longitude, gospec.Equals, 112.5584077835083)
	})
}
開發者ID:RUNDSP,項目名稱:ggeohash,代碼行數:11,代碼來源:decode_bound_box_test.go

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

示例5: MatrixIndexerSpec

func MatrixIndexerSpec(c gospec.Context) {
	size := 100
	usedIds := make(map[int]bool)
	nodesIds := make(map[VertexId]int)
	for i := 0; i < size; i++ {
		for j := 0; j < i; j++ {
			connId := matrixConnectionsIndexer(VertexId(i), VertexId(j), nodesIds, size, true)
			_, ok := usedIds[connId]
			c.Expect(ok, IsFalse)
			usedIds[connId] = true
		}
	}
}
開發者ID:tusj,項目名稱:go-graph,代碼行數:13,代碼來源:stuff_test.go

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

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

示例8: NewArray3Spec

func NewArray3Spec(c gospec.Context) {
	d100x20x10 := NewArray3(100, 20, 10)
	c.Specify("Allocates the appropriate memory for 3D arrays.", func() {
		n0, n1, n2 := d100x20x10.Dims()
		c.Expect(n0, gospec.Equals, 100)
		c.Expect(n1, gospec.Equals, 20)
		c.Expect(n2, gospec.Equals, 10)
		var counter float32 = 0.0
		for i := 0; i < n0; i++ {
			for j := 0; j < n1; j++ {
				for k := 0; k < n2; k++ {
					d100x20x10.Set(i, j, k, complex(counter, 0))
					counter += 1.0
				}
			}
		}
		counter = 0.0
		for i := 0; i < n0; i++ {
			for j := 0; j < n1; j++ {
				for k := 0; k < n2; k++ {
					c.Expect(real(d100x20x10.At(i, j, k)), gospec.Equals, counter)
					counter += 1.0
				}
			}
		}
	})
}
開發者ID:jvlmdr,項目名稱:go-fftw,代碼行數:27,代碼來源:fftw_test.go

示例9: Mapper2Spec

func Mapper2Spec(c gospec.Context) {
	c.Specify("Map from []int to []float64", func() {
		a := []int{0, 1, 2, 3, 4}
		var b []float64
		algorithm.Map2(a, &b, func(n int) float64 { return float64(n) })
		c.Expect(b, ContainsInOrder, []float64{0, 1, 2, 3, 4})
	})
	// c.Specify("Map from []int to []string", func() {
	//   a := []int{0,1,2,3,4}
	//   var b []string
	//   b = algorithm.Map(a, []string{}, func(v interface{}) interface{} { return fmt.Sprintf("%d", v) }).([]string)
	//   c.Expect(b, ContainsInOrder, []string{"0", "1", "2", "3", "4"})
	// })
}
開發者ID:runningwild,項目名稱:glop,代碼行數:14,代碼來源:generic_test.go

示例10: CMWCSpec

func CMWCSpec(c gospec.Context) {
	c.Specify("CMWC32 produces the same output as SlowCMWC.", func() {
		fast := core.MakeCMWC32(11, 4)
		slow := core.MakeSlowCMWC(11, 1<<32, 1<<4)
		N := 100000
		for i := 0; i < N; i++ {
			f := fast.Next()
			s := slow.Next()
			c.Expect(f, Equals, s)
			if f != s {
				break
			}
		}
	})
}
開發者ID:runningwild,項目名稱:cmwc,代碼行數:15,代碼來源:cmwc_test.go

示例11: QuebraLinhaTest

func QuebraLinhaTest(c gospec.Context) {
	c.Specify("Caso texto seja menor q tamanho maximo", func() {
		c.Expect(QuebraLinha("ola mundo", 14), Equals, "ola mundo")
	})

	c.Specify("Caso texto seja maior q tamanho maximo", func() {
		c.Expect(QuebraLinha("lavarini lindo demais", 15), Equals, "lavarini lindo\ndemais")
	})
}
開發者ID:cicerocomp,項目名稱:Dojo,代碼行數:9,代碼來源:quebra_de_linha_test.go

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

示例13: BellmanFordSingleSourceSpec

func BellmanFordSingleSourceSpec(c gospec.Context) {
	gr := generateDirectedGraph1()

	marks := BellmanFordSingleSource(gr, VertexId(2), SimpleWeightFunc)
	c.Expect(len(marks), Equals, gr.Order())

	c.Expect(PathFromMarks(marks, VertexId(6)), ContainsExactly, Values(VertexId(2), VertexId(6)))
	c.Expect(PathFromMarks(marks, VertexId(5)), ContainsExactly, Values(VertexId(2), VertexId(4), VertexId(5)))
	c.Expect(PathFromMarks(marks, VertexId(1)), ContainsExactly, Values())
}
開發者ID:tusj,項目名稱:go-graph,代碼行數:10,代碼來源:search_test.go

示例14: NewArraySpec

func NewArraySpec(c gospec.Context) {
	d10 := NewArray(10)
	d100 := NewArray(100)
	d1000 := NewArray(1000)
	c.Specify("Allocates the appropriate memory for 1D arrays.", func() {
		c.Expect(len(d10.Elems), gospec.Equals, 10)
		c.Expect(len(d100.Elems), gospec.Equals, 100)
		c.Expect(len(d1000.Elems), gospec.Equals, 1000)
	})
}
開發者ID:jvlmdr,項目名稱:go-fftw,代碼行數:10,代碼來源:fftw_test.go

示例15: Alloc1dSpec

func Alloc1dSpec(c gospec.Context) {
	d10 := Alloc1d(10)
	d100 := Alloc1d(100)
	d1000 := Alloc1d(1000)
	c.Specify("Allocates the appropriate memory for 1d arrays.", func() {
		c.Expect(len(d10), gospec.Equals, 10)
		c.Expect(len(d100), gospec.Equals, 100)
		c.Expect(len(d1000), gospec.Equals, 1000)
	})
}
開發者ID:jtc25,項目名稱:go-fftw,代碼行數:10,代碼來源:fftw_test.go


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