Esempio n. 1
0
func main() {
	if Same(tree.New(1), tree.New(1)) {
		fmt.Println("Same!")
	} else {
		fmt.Println("not Same!")
	}
}
Esempio n. 2
0
func main() {
	if Same(tree.New(1), tree.New(2)) {
		fmt.Println("Yay!")
	} else {
		fmt.Println("Nay!")
	}
}
Esempio n. 3
0
func main() {
	t1 := tree.New(1)
	t2 := tree.New(1)

	fmt.Println(Same(t1, t2))

}
Esempio n. 4
0
// C70 ...
func C70(opts Options, args []string) int {
	t1 := tree.New(1)
	t2 := tree.New(1)
	fmt.Println(t1)
	fmt.Println(t2)
	fmt.Println(same(t1, t2))
	return 0
}
Esempio n. 5
0
func main() {
	//    ch := make(chan int)
	//    go Walk(tree.New(1), ch)
	//    for i := 0; i < 10; i++ {
	//      fmt.Println(<-ch)
	//    }
	fmt.Println(Same(tree.New(1), tree.New(1)))
	fmt.Println(Same(tree.New(1), tree.New(2)))
}
Esempio n. 6
0
func main() {
	ch := make(chan int)
	go Walk(tree.New(1), ch)
	for i := range ch {
		fmt.Println(i)
	}
	fmt.Println(Same(tree.New(1), tree.New(1)))
	fmt.Println(Same(tree.New(1), tree.New(2)))
}
func TestSame(t *testing.T) {
	if !Same(tree.New(1), tree.New(1)) {
		t.Errorf("Expect tree.New(1) is the same with tree.New(1)")
	}

	if Same(tree.New(1), tree.New(2)) {
		t.Errorf("Expect tree.New(1) is not the same with tree.New(2)")
	}
}
Esempio n. 8
0
func main() {
	ch := make(chan int)
	go Walk(tree.New(1), ch)
	for i := 0; i < 10; i++ {
		print(<-ch, " ")
	}
	print("\n")
	println(Same(tree.New(1), tree.New(1)),
		Same(tree.New(2), tree.New(1)))
}
Esempio n. 9
0
func main() {
	ch := make(chan int)
	go Walk(tree.New(1), ch)
	for i := 0; i < 10; i++ {
		fmt.Println(<-ch)
	}

	fmt.Println(Same(tree.New(1), tree.New(1)))
	fmt.Println(Same(tree.New(1), tree.New(2)))
}
Esempio n. 10
0
func main() {
	if !Same(tree.New(1), tree.New(1)) {
		fmt.Println("fail!! 1 && 1")
		return
	}
	if Same(tree.New(1), tree.New(2)) {
		fmt.Println("fail!! 1 && 2")
		return
	}
	fmt.Println("all succeed!")
}
Esempio n. 11
0
func main() {
	ch := make(chan int)
	go Walk(tree.New(1), ch)
	for n := range ch {
		print(n, " ")
	}
	println()

	println(Same(tree.New(1), tree.New(1)))
	println(Same(tree.New(1), tree.New(2)))
}
func main() {
	t1 := tree.New(1)
	/*
	   ch := make(chan int, 10)
	   go Walk(t1, ch)
	   for val := range(ch){
	       fmt.Println(val)
	   }
	*/
	fmt.Println(Same(t1, tree.New(1)))
	fmt.Println(Same(t1, tree.New(2)))
}
Esempio n. 13
0
func main() {
	t := tree.New(1)
	t2 := tree.New(1)
	fmt.Println(t)
	fmt.Println(t2)
	c := make(chan int)
	go Walk(t, c)
	for i := 0; i < 10; i++ {
		fmt.Println(<-c)
	}
	fmt.Println(Same(t, t2))
}
Esempio n. 14
0
func page68_Exercise_EquivalentBinaryTrees() {
	// test Walk
	/*
		ch := make(chan int)
		go Walk(tree.New(1), ch)
		for i := 0; i < 10; i++ {
			fmt.Println(<-ch)
		}
	*/

	fmt.Println(Same(tree.New(1), tree.New(1)))
	fmt.Println(Same(tree.New(1), tree.New(2)))
}
Esempio n. 15
0
func Exercise11() {
	// Uncomment to test Walk

	// ch := make(chan int)
	// go Walk(tree.New(1), ch)
	//
	// for v := range ch {
	// 	fmt.Printf("%d\n", v)
	// }

	fmt.Printf("tree.New(1) == tree.New(1) is %t\n", Same(tree.New(1), tree.New(1)))
	fmt.Printf("tree.New(1) == tree.New(2) is %t\n", Same(tree.New(1), tree.New(2)))
}
Esempio n. 16
0
func main() {
	ch := make(chan int)

	// test Walk
	go Walk(tree.New(1), ch)
	for n := range ch {
		fmt.Print(n)
	}
	fmt.Println()

	// test Same
	fmt.Println(Same(tree.New(1), tree.New(1))) // should be true
	fmt.Println(Same(tree.New(1), tree.New(2))) // should be false
}
Esempio n. 17
0
func main() {
	rand.Seed(time.Now().UTC().UnixNano())
	t1, t2 := tree.New(1), tree.New(2)

	log.Println("t1: ", t1)
	//dump(t1)

	log.Println("t2: ", t2)
	//dump(t2)

	log.Println("t1 == t1? ", Same(t1, t1, 1))
	log.Println("t2 == t2? ", Same(t2, t2, 1))
	log.Println("t1 == t2? ", Same(t1, t2, 2))
}
Esempio n. 18
0
func main() {
	ch := make(chan int)
	t1 := tree.New(1)
	t2 := tree.New(2)

	// fmt.Println(PyutaWalk(t1))
	// foreachNode(t1)

	go Walk(t1, ch)
	for c := range ch {
		fmt.Println(c)
	}
	fmt.Printf("%v\n", Same(t1, t2))
}
Esempio n. 19
0
File: tour71.go Progetto: roca/GO
func main() {

	t1 := tree.Tree{
		&tree.Tree{
			&tree.Tree{
				nil,
				1,
				nil,
			},
			1,
			&tree.Tree{
				nil,
				2,
				nil,
			},
		},
		3,
		&tree.Tree{
			&tree.Tree{
				nil,
				5,
				nil,
			},
			8,
			&tree.Tree{
				nil,
				13,
				nil,
			},
		},
	}
	t2 := tree.Tree{
		&tree.Tree{
			&tree.Tree{
				&tree.Tree{nil, 1, nil},
				1,
				&tree.Tree{nil, 2, nil},
			},
			3,
			&tree.Tree{nil, 5, nil},
		},
		8,
		&tree.Tree{nil, 13, nil},
	}

	fmt.Println("Are they the same ?", Same(&t1, &t2))
	fmt.Println("Are they the same ?", Same(tree.New(1), tree.New(1)))
	fmt.Println("Are they the same ?", Same(tree.New(1), tree.New(2)))
}
Esempio n. 20
0
func main() {
	fmt.Print("tree.New(1) == tree.New(1): ")
	if Same(tree.New(1), tree.New(1)) {
		fmt.Println("PASSED")
	} else {
		fmt.Println("FAILED")
	}

	fmt.Print("tree.New(1) != tree.New(2): ")
	if !Same(tree.New(1), tree.New(2)) {
		fmt.Println("PASSED")
	} else {
		fmt.Println("FAILED")
	}
}
Esempio n. 21
0
func main() {
	// test Walk()
	ch := make(chan int)
	go Walk(tree.New(1), ch)
	for i := 1; i <= 10; i++ {
		ii := <-ch
		if ii != i {
			fmt.Println("Walk Error, doesn't match!")
		}
	}

	// test Same()
	fmt.Println("Same(tree.New(1), tree.New(1)): ", Same(tree.New(1), tree.New(1)))
	fmt.Println("Same(tree.New(1), tree.New(2)): ", Same(tree.New(1), tree.New(2)))
}
Esempio n. 22
0
File: main.go Progetto: kkdai/Golang
func main() {
	//tt := tree.New(1)
	//fmt.Println("out tree=", tt.String())
	ch := make(chan int)
	go Walk(tree.New(1), ch)
	for v := range ch {
		fmt.Println(v)
	}

	if Same(tree.New(1), tree.New(2)) {
		fmt.Println("is the sam")
	} else {
		fmt.Println("is not the same ")
	}

}
Esempio n. 23
0
func main() {
	ch := make(chan int)
	go Walk(tree.New(10), ch)
	for elem := range ch {
		fmt.Println(elem)
	}
}
func main() {
	t1 := tree.New(1)
	t1prime := tree.New(1)
	t2 := tree.New(2)

	if Same(t1, t1prime) {
		fmt.Println("Success: 1-based trees are equal as expected")
	} else {
		fmt.Println("Error: 1-based trees are not equal, but should be")
	}

	if Same(t1, t2) {
		fmt.Println("Error: 1- and 2-based trees are equal, but shouldn't be")
	} else {
		fmt.Println("Success: 1- and 2-based trees are not equal")
	}
}
Esempio n. 25
0
func main() {
	// Walk test
	t1 := tree.New(1)

	ch := make(chan int)
	go Walk(t1, ch)

	for i := 0; i < 10; i++ {
		fmt.Println(<-ch)
	}

	// Same test
	t2 := tree.New(1)
	fmt.Println(Same(t1, t2))
	t3 := tree.New(2)
	fmt.Println(Same(t1, t3))
}
Esempio n. 26
0
func main() {
	ch := make(chan int)
	go Walk(tree.New(1), ch)
	for i := 0; i < 10; i++ {
		v := <-ch
		fmt.Println(v)
	}
}
Esempio n. 27
0
func main() {
	// test Walk()
	t := tree.New(1)
	ch := make(chan int)
	go Walk(t, ch)
	testWalk := true
	for i := 0; i < 10; i++ {
		if i+1 != <-ch {
			testWalk = false
			break
		}
	}
	fmt.Println("Test Walk() passed: ", testWalk)

	fmt.Println("Same(tree.New(1), tree.New(1))", Same(tree.New(1), tree.New(1)))
	fmt.Println("Same(tree.New(1), tree.New(2))", Same(tree.New(1), tree.New(2)))
}
Esempio n. 28
0
func main() {
	// Test the Walk function
	ch := make(chan int)
	go Walk(tree.New(1), ch)
	v, ok := <-ch
	for ok {
		fmt.Printf("%d,", v)
		v, ok = <-ch
		if !ok {
			fmt.Printf("done...\n")
		}
	}

	// Test the Same function:
	fmt.Println(Same(tree.New(1), tree.New(1)))
	fmt.Println(Same(tree.New(1), tree.New(3)))
}
Esempio n. 29
0
func main() {
	fmt.Println()
	ch := make(chan int)

	// the channel can not be closed in main so stick it in an anonomous func?
	// This does mean they start traversing straight away...
	go func() {
		Walk(tree.New(1), ch)
		close(ch)
	}()

	for v := range ch {
		fmt.Println(v)
	}

	fmt.Println(Same(tree.New(1), tree.New(1)))
	fmt.Println(Same(tree.New(1), tree.New(2)))

}
Esempio n. 30
0
func main() {
	ch := make(chan int)
	go Walk(tree.New(1), ch)
	for v := range ch {
		fmt.Println(v)
	}

	if Same(tree.New(1), tree.New(1)) {
		fmt.Println("ok")
	} else {
		fmt.Println("ng")
	}

	if !Same(tree.New(1), tree.New(2)) {
		fmt.Println("ok")
	} else {
		fmt.Println("ng")
	}
}