当前位置: 首页>>代码示例>>Golang>>正文


Golang T.ToString方法代码示例

本文整理汇总了Golang中testing.T.ToString方法的典型用法代码示例。如果您正苦于以下问题:Golang T.ToString方法的具体用法?Golang T.ToString怎么用?Golang T.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在testing.T的用法示例。


在下文中一共展示了T.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestIterator

func TestIterator(t *testing.T) {
	var ts *LevelDBTripleStore

	Convey("Given a prepared database", t, func() {
		tmpDir, _ := ioutil.TempDir(os.TempDir(), "cayley_test")
		t.Log(tmpDir)
		defer os.RemoveAll(tmpDir)
		ok := CreateNewLevelDB(tmpDir)
		So(ok, ShouldBeTrue)
		ts = NewDefaultLevelDBTripleStore(tmpDir, nil)
		ts.AddTripleSet(makeTripleSet())
		var it graph.Iterator

		Convey("Can create an all iterator for nodes", func() {
			it = ts.GetNodesAllIterator()
			So(it, ShouldNotBeNil)

			Convey("Has basics", func() {
				size, accurate := it.Size()
				So(size, ShouldBeBetween, 0, 20)
				So(accurate, ShouldBeFalse)
				So(it.Type(), ShouldEqual, "all")
				re_it, ok := it.Optimize()
				So(ok, ShouldBeFalse)
				So(re_it, ShouldPointTo, it)
			})

			Convey("Iterates all nodes", func() {
				expected := []string{
					"A",
					"B",
					"C",
					"D",
					"E",
					"F",
					"G",
					"follows",
					"status",
					"cool",
					"status_graph",
				}
				sort.Strings(expected)
				actual := extractValuesFromIterator(ts, it)
				sort.Strings(actual)
				So(actual, ShouldResemble, expected)
				it.Reset()
				actual = extractValuesFromIterator(ts, it)
				sort.Strings(actual)
				So(actual, ShouldResemble, expected)

			})

			Convey("Contains a couple nodes", func() {
				So(it.Check(ts.GetIdFor("A")), ShouldBeTrue)
				So(it.Check(ts.GetIdFor("cool")), ShouldBeTrue)
				//So(it.Check(ts.GetIdFor("baller")), ShouldBeFalse)
			})

			Reset(func() {
				it.Reset()
			})
		})

		Convey("Can create an all iterator for edges", func() {
			it := ts.GetTriplesAllIterator()
			So(it, ShouldNotBeNil)
			Convey("Has basics", func() {
				size, accurate := it.Size()
				So(size, ShouldBeBetween, 0, 20)
				So(accurate, ShouldBeFalse)
				So(it.Type(), ShouldEqual, "all")
				re_it, ok := it.Optimize()
				So(ok, ShouldBeFalse)
				So(re_it, ShouldPointTo, it)
			})

			Convey("Iterates an edge", func() {
				edge_val, _ := it.Next()
				triple := ts.GetTriple(edge_val)
				set := makeTripleSet()
				var string_set []string
				for _, t := range set {
					string_set = append(string_set, t.ToString())
				}
				So(triple.ToString(), ShouldBeIn, string_set)
			})

			Reset(func() {
				ts.Close()
			})
		})
	})

}
开发者ID:java10000,项目名称:cayley,代码行数:94,代码来源:leveldb_test.go

示例2: TestValue

func TestValue(t *testing.T) {

	Convey("steps method", t, func() {
		tasks := readBook(".files/1st.yaml")
		steps := tasks[0].Series
		fmt.Println(tasks[0].Name)
		So(steps, ShouldNotBeNil)
		So(len(steps), ShouldEqual, 2)
	})

	Convey("book steps has specific type", t, func() {
		tasks := readBook(".files/1st.yaml")
		steps := tasks[0].Parallel
		So(steps, ShouldNotBeNil)
		So(len(steps), ShouldEqual, 0)
	})

	Convey("walking path produces value", t, func() {
		a := make(map[string]interface{})
		a["stuff"] = "where"
		b := make(map[string]interface{})
		b["here"] = a

		u := NewValue(b)
		u = u.To("here.stuff")

		So(u.ToString(), ShouldEqual, "where")
	})

	Convey("should get the 'here' value from the map", t, func() {
		m := make(map[string]string)
		m["here"] = "there"
		t := NewValue(m)
		t = t.Get("here")
		So(t.HasValue(), ShouldBeTrue)
		So(t.IsMap(), ShouldBeFalse)
		So(t.ToString(), ShouldEqual, "there")
	})

	Convey("using a path to a value that EXISTS should produce that value", t, func() {
		m := createMap()
		t := NewValue(m)
		t = t.Get("here")
		So(t.HasValue(), ShouldBeTrue)
		So(t.IsMap(), ShouldBeFalse)
		So(t.ToInt(), ShouldEqual, 1)
	})

	Convey("converting with just key", t, func() {
		m := make(map[string]string)
		m["here"] = "stuff"
		h := reflect.ValueOf("here")
		actual := reflect.ValueOf(m).MapIndex(h)
		val := actual.Interface()
		So(val, ShouldEqual, "stuff")
	})

	Convey("should be true that Value with 1 has a Value and that value is not a map", t, func() {
		t := NewValue(1)
		So(t.HasValue(), ShouldBeTrue)
		So(t.IsMap(), ShouldBeFalse)
	})

	Convey("should be true that Value with 1 has a Value and that value is not a map", t, func() {
		types := []interface{}{
			make(map[string]string),
			make(map[string]int),
			make(map[string]interface{}),
			make(map[interface{}]interface{}),
		}
		for _, k := range types {
			t := NewValue(k)
			So(t.HasValue(), ShouldBeTrue)
			isMap := t.IsMap()
			if !isMap {
				dumpType(k)
			}
			So(isMap, ShouldBeTrue)
		}
	})

	Convey("using a path to a value that DOESN'T exist should produce nil value", t, func() {
		m := createMap()
		t := NewValue(m)
		t = t.Get("nope")
		So(t.HasValue(), ShouldBeFalse)
		So(t.IsMap(), ShouldBeFalse)
	})

	Convey("a map backed Value should return true for isMap", t, func() {
		m := createMap()
		t := NewValue(m)
		So(t.IsMap(), ShouldBeTrue)
	})

	Convey("a map backed Value should have a 'value'", t, func() {
		m := createMap()
		t := NewValue(m)
		So(t.values, ShouldNotBeNil)
		So(t.HasValue(), ShouldBeTrue)
//.........这里部分代码省略.........
开发者ID:lcaballero,项目名称:pregame,代码行数:101,代码来源:value_test.go


注:本文中的testing.T.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。