Пример #1
0
func printResults(results []*transaction.Transaction, emit func(string)) {
	var width int
	for _, t := range results {
		mw := t.MinimumWidth()
		if mw > width {
			width = mw
		}
	}

	sort.Sort(transaction.TransactionList(results))
	for _, t := range results {
		emit(t.Format(width + 3))
	}
}
Пример #2
0
			t2   *transaction.Transaction
			t3   *transaction.Transaction
			list transaction.TransactionList
		)

		BeforeEach(func() {
			t1 = &transaction.Transaction{
				Date: transaction.NewDate(2012, 1, 1),
			}
			t2 = &transaction.Transaction{
				Date: transaction.NewDate(2013, 1, 1),
			}
			t3 = &transaction.Transaction{
				Date: transaction.NewDate(2011, 1, 1),
			}
			list = transaction.TransactionList([]*transaction.Transaction{
				t1,
				t2,
				t3,
			})
		})

		It("is sortable", func() {
			sort.Sort(list)
			Expect(list[0]).To(Equal(t3))
			Expect(list[1]).To(Equal(t1))
			Expect(list[2]).To(Equal(t2))
		})
	})
})