github.com/bigzoro/my_simplechain@v0.0.0-20240315012955-8ad0a2a29bb9/core/dag/dag_test.go (about) 1 // Copyright 2020 The go-simplechain Authors 2 // This file is part of the go-simplechain library. 3 // 4 // The go-simplechain library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-simplechain library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-simplechain library. If not, see <http://www.gnu.org/licenses/>. 16 17 package dag 18 19 import ( 20 "fmt" 21 "os" 22 "testing" 23 24 "github.com/bigzoro/my_simplechain/log" 25 ) 26 27 func TestDag(t *testing.T) { 28 29 log.Root().SetHandler(log.CallerFileHandler(log.LvlFilterHandler(log.Lvl(4), log.StreamHandler(os.Stderr, log.TerminalFormat(true))))) 30 dag := NewDag(10) 31 dag.AddEdge(0, 1) 32 dag.AddEdge(0, 2) 33 dag.AddEdge(3, 4) 34 dag.AddEdge(3, 5) 35 dag.AddEdge(1, 6) 36 dag.AddEdge(2, 6) 37 dag.AddEdge(4, 6) 38 dag.AddEdge(5, 6) 39 dag.AddEdge(6, 7) 40 dag.AddEdge(7, 8) 41 dag.AddEdge(7, 9) 42 43 buff, err := dag.Print() 44 if err != nil { 45 fmt.Print("print DAG Graph error!", err) 46 } 47 fmt.Printf("DAG Graph for blockNumber:%d\n%s", 1, buff.String()) 48 49 fmt.Printf("iterate over second times") 50 for dag.HasNext() { 51 ids := dag.Next() 52 fmt.Printf("ids:%+v", ids) 53 } 54 55 }