Esempio n. 1
0
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
}
Esempio n. 2
0
func BenchmarkAddStringSlice(b *testing.B) {
	for n := 0; n < b.N; n++ {
		s := gotility.StringSlice{}
		s.Add("test")
	}
}
Esempio n. 3
0
	}
}

var benchmarkStringSliceContains = gotility.RandomStringSlice(100, "foo", "bar", "baz")

func BenchmarkContains(b *testing.B) {
	benchmarkStringSliceContains.Add("needle")
	for n := 0; n < b.N; n++ {
		benchmarkStringSliceContains.Contains("needle")
	}
}

var _ = Describe("StringSlice", func() {
	It("should add one element", func() {
		s := gotility.StringSlice{}
		s.Add("foo")
		Expect(s).To(ConsistOf([]string{"foo"}))
	})

	It("should add all elements", func() {
		s := gotility.StringSlice{}
		s.AddAll("foo", "bar", "baz")
		Expect(s).To(ConsistOf([]string{"foo", "bar", "baz"}))
	})

	It("should delete elements by index", func() {
		s := gotility.StringSlice{}
		Expect(s.DeleteByIndex(0)).To(BeFalse())
		Expect(s.DeleteByIndex(-1)).To(BeFalse())
		Expect(s.DeleteByIndex(42)).To(BeFalse())