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


Golang Iterator.Reset方法代碼示例

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


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

示例1: TestSetIterator

func TestSetIterator(t *testing.T) {
    var ts *LevelDBTripleStore
    var tmpDir string

    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 a subject iterator", func() {
            it = ts.GetTripleIterator("s", ts.GetIdFor("C"))

            Convey("Containing the right things", func() {
                expected := []string{
                    graph.MakeTriple("C", "follows", "B", "").ToString(),
                    graph.MakeTriple("C", "follows", "D", "").ToString(),
                }
                actual := extractTripleFromIterator(ts, it)
                sort.Strings(actual)
                sort.Strings(expected)
                So(actual, ShouldResemble, expected)
            })

            Convey("And checkable", func() {
                and := graph.NewAndIterator()
                and.AddSubIterator(ts.GetTriplesAllIterator())
                and.AddSubIterator(it)

                expected := []string{
                    graph.MakeTriple("C", "follows", "B", "").ToString(),
                    graph.MakeTriple("C", "follows", "D", "").ToString(),
                }
                actual := extractTripleFromIterator(ts, and)
                sort.Strings(actual)
                sort.Strings(expected)
                So(actual, ShouldResemble, expected)
            })
            Reset(func() {
                it.Reset()
            })

        })

        Convey("Can create an object iterator", func() {
            it = ts.GetTripleIterator("o", ts.GetIdFor("F"))

            Convey("Containing the right things", func() {
                expected := []string{
                    graph.MakeTriple("B", "follows", "F", "").ToString(),
                    graph.MakeTriple("E", "follows", "F", "").ToString(),
                }
                actual := extractTripleFromIterator(ts, it)
                sort.Strings(actual)
                sort.Strings(expected)
                So(actual, ShouldResemble, expected)
            })

            Convey("Mutually and-checkable", func() {
                and := graph.NewAndIterator()
                and.AddSubIterator(ts.GetTripleIterator("s", ts.GetIdFor("B")))
                and.AddSubIterator(it)

                expected := []string{
                    graph.MakeTriple("B", "follows", "F", "").ToString(),
                }
                actual := extractTripleFromIterator(ts, and)
                sort.Strings(actual)
                sort.Strings(expected)
                So(actual, ShouldResemble, expected)
            })

        })

        Convey("Can create a predicate iterator", func() {
            it = ts.GetTripleIterator("p", ts.GetIdFor("status"))

            Convey("Containing the right things", func() {
                expected := []string{
                    graph.MakeTriple("B", "status", "cool", "status_graph").ToString(),
                    graph.MakeTriple("D", "status", "cool", "status_graph").ToString(),
                    graph.MakeTriple("G", "status", "cool", "status_graph").ToString(),
                }
                actual := extractTripleFromIterator(ts, it)
                sort.Strings(actual)
                sort.Strings(expected)
                So(actual, ShouldResemble, expected)
            })

        })

        Convey("Can create a provenance iterator", func() {
            it = ts.GetTripleIterator("c", ts.GetIdFor("status_graph"))

            Convey("Containing the right things", func() {
                expected := []string{
//.........這裏部分代碼省略.........
開發者ID:JIVS,項目名稱:cayley,代碼行數:101,代碼來源:leveldb_test.go

示例2: TestAllIterator

func TestAllIterator(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:JIVS,項目名稱:cayley,代碼行數:94,代碼來源:leveldb_test.go


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