コード例 #1
0
ファイル: endpoint_tree.go プロジェクト: fgrosse/tigs
func (t endpointTree) checkForCycles(node *endpointNode, trace gotility.StringSlice) error {
	for _, child := range node.children {
		if trace.Contains(child.Name) {
			trace.Add(child.Name)
			trace.Reverse()
			return fmt.Errorf("Detected inheritance cycle: %s", strings.Join(trace, " -> "))
		}

		trace.Add(child.Name)
		if err := t.checkForCycles(child, trace); err != nil {
			return err
		}
		trace.DeleteByValue(child.Name)
	}

	return nil
}
コード例 #2
0
ファイル: string_slice_test.go プロジェクト: fgrosse/gotility
		Expect(s).To(ConsistOf([]string{}))
	})

	It("should know if it contains a string", func() {
		s := gotility.StringSlice{}
		Expect(s.Contains("foo")).To(BeFalse())

		s = gotility.StringSlice{"foo", "bar"}
		Expect(s.Contains("foo")).To(BeTrue())
		Expect(s.Contains("bar")).To(BeTrue())
		Expect(s.Contains("baz")).To(BeFalse())
	})

	It("should be able to reverse its elements", func() {
		s := gotility.StringSlice{}
		s.Reverse()
		Expect(s).To(BeEmpty())

		s = gotility.StringSlice{"foo", "bar", "baz", "1", "2"}
		s.Reverse()
		Expect(s).To(Equal(gotility.StringSlice{"2", "1", "baz", "bar", "foo"}))
		s.Reverse()
		Expect(s).To(Equal(gotility.StringSlice{"foo", "bar", "baz", "1", "2"}))

		s = gotility.StringSlice{"1", "2", "3", "4"}
		s.Reverse()
		Expect(s).To(Equal(gotility.StringSlice{"4", "3", "2", "1"}))
	})
})

var _ = Describe("RandomStringSlice", func() {