raw3, err := columnTypes[0].PersistRawFromString("3.0")
				Ω(err).ShouldNot(HaveOccurred())

				target1, err = slice.SliceFromRawValues(true, []int{0}, columnTypes, []float64{raw1})
				target2, err = slice.SliceFromRawValues(true, []int{0}, columnTypes, []float64{raw2})
				target3, err = slice.SliceFromRawValues(true, []int{0}, columnTypes, []float64{raw3})
			})

			Context("When the collection has fewer than k candidates", func() {
				BeforeEach(func() {
					stc.Insert(target1, 23.0)
				})

				It("Chooses the winner", func() {
					winner := stc.Vote()
					Ω(target1.Equals(winner)).Should(BeTrue())
				})
			})

			Context("When there is a clear winner", func() {
				BeforeEach(func() {
					stc.Insert(target1, 23.0)
					stc.Insert(target2, 40.0)
					stc.Insert(target2, 50.0)
					stc.Insert(target2, 90.0)
					stc.Insert(target3, 10.0)
				})

				It("Chooses the winner", func() {
					winner := stc.Vote()
					Ω(target2.Equals(winner)).Should(BeTrue())
Exemplo n.º 2
0
	Describe("SliceFromRawValues and Equals", func() {
		var columnTypes []columntype.ColumnType
		var err error
		var s1, s2 slice.Slice

		Context("Given slices of different lengths", func() {
			BeforeEach(func() {
				columnTypes, err = columntype.StringsToColumnTypes([]string{"1.0", "1.0"})
				Ω(err).ShouldNot(HaveOccurred())
			})

			It("returns false", func() {
				s1, _ = slice.SliceFromRawValues(true, []int{}, columnTypes, []float64{0.0, 1.0})
				s2, _ = slice.SliceFromRawValues(true, []int{0}, columnTypes, []float64{0.0, 1.0})

				Ω(s1.Equals(s2)).Should(BeFalse())
			})
		})

		Context("Given slices with different values", func() {
			BeforeEach(func() {
				columnTypes, err = columntype.StringsToColumnTypes([]string{"1.0", "1.0"})
				Ω(err).ShouldNot(HaveOccurred())
			})

			It("returns false", func() {
				s1, _ = slice.SliceFromRawValues(true, []int{1}, columnTypes, []float64{0.0, 1.0})
				s2, _ = slice.SliceFromRawValues(true, []int{0}, columnTypes, []float64{0.0, 1.0})

				Ω(s1.Equals(s2)).Should(BeFalse())
			})