<commit_before>package pricing

import (
	"math/big"
	"testing"
	"time"

	. "github.com/smartystreets/goconvey/convey"
)

func TestNewBasket(t *testing.T) {
	Convey("Testing NewBasket()", t, func() {
		basket := NewBasket()
		So(basket, ShouldNotBeNil)
		So(basket.Length(), ShouldEqual, 0)
	})
}

func TestBasket_Add(t *testing.T) {
	Convey("Testing Basket.Add", t, FailureContinues, func() {
		basket := NewBasket()
		So(basket, ShouldNotBeNil)
		So(basket.Length(), ShouldEqual, 0)

		err := basket.Add(NewUsageByPathWithQuantity("/compute/c1/run", big.NewRat(1, 1)))
		So(err, ShouldBeNil)
		So(basket.Length(), ShouldEqual, 1)

		err = basket.Add(NewUsageByPathWithQuantity("/compute/c1/run", big.NewRat(42, 1)))
		So(err, ShouldBeNil)
		So(basket.Length(), ShouldEqual, 2)

		err = basket.Add(NewUsageByPathWithQuantity("/compute/c1/run", big.NewRat(600, 1)))
		So(err, ShouldBeNil)
		So(basket.Length(), ShouldEqual, 3)
	})
}

func TestBasket_Total(t *testing.T) {
	Convey("Testing Basket.Total", t, FailureContinues, func() {
		Convey("3 compute instances", func() {
			basket := NewBasket()
			So(basket, ShouldNotBeNil)
			So(basket.Total(), ShouldEqualBigRat, ratZero)

			err := basket.Add(NewUsageByPathWithQuantity("/compute/c1/run", big.NewRat(1, 1)))
			So(err, ShouldBeNil)
			So(basket.Total(), ShouldEqualBigRat, big.NewRat(72, 100)) // 0.72

			err = basket.Add(NewUsageByPathWithQuantity("/compute/c1/run", big.NewRat(42, 1)))
			So(err, ShouldBeNil)
			So(basket.Total(), ShouldEqualBigRat, big.NewRat(144, 100)) // 1.44

			err = basket.Add(NewUsageByPathWithQuantity("/compute/c1/run", big.NewRat(600, 1)))
			So(err, ShouldBeNil)
			So(basket.Total(), ShouldEqualBigRat, big.NewRat(744, 100)) // 7.44
		})
		Convey("1 compute instance with 2 volumes and 1 ip", func() {
			basket := NewBasket()

			basket.Add(NewUsageByPath("/compute/c1/run"))
			basket.Add(NewUsageByPath("/ip/dynamic"))
			basket.Add(NewUsageByPath("/storage/local/ssd/storage"))
			basket.Add(NewUsageByPath("/storage/local/ssd/storage"))
			So(basket.Length(), ShouldEqual, 4)

			basket.SetDuration(1 * time.Minute)
			So(basket.Total(), ShouldEqualBigRat, big.NewRat(136, 100)) // 1.36

			basket.SetDuration(1 * time.Hour)
			So(basket.Total(), ShouldEqualBigRat, big.NewRat(136, 100)) // 1.36

			basket.SetDuration(2 * time.Hour)
			So(basket.Total(), ShouldEqualBigRat, big.NewRat(232, 100)) // 2.32

			basket.SetDuration(2 * 24 * time.Hour)
			So(basket.Total(), ShouldEqualBigRat, big.NewRat(8399, 1000)) // 8.399

			basket.SetDuration(30 * 24 * time.Hour)
			So(basket.Total(), ShouldEqualBigRat, big.NewRat(11999, 1000)) // 11.999
		})
	})
}<commit_msg>Added a false-positive test for future development<commit_after>package pricing

import (
	"math/big"
	"testing"
	"time"

	. "github.com/smartystreets/goconvey/convey"
)

func TestNewBasket(t *testing.T) {
	Convey("Testing NewBasket()", t, func() {
		basket := NewBasket()
		So(basket, ShouldNotBeNil)
		So(basket.Length(), ShouldEqual, 0)
	})
}

func TestBasket_Add(t *testing.T) {
	Convey("Testing Basket.Add", t, FailureContinues, func() {
		basket := NewBasket()
		So(basket, ShouldNotBeNil)
		So(basket.Length(), ShouldEqual, 0)

		err := basket.Add(NewUsageByPathWithQuantity("/compute/c1/run", big.NewRat(1, 1)))
		So(err, ShouldBeNil)
		So(basket.Length(), ShouldEqual, 1)

		err = basket.Add(NewUsageByPathWithQuantity("/compute/c1/run", big.NewRat(42, 1)))
		So(err, ShouldBeNil)
		So(basket.Length(), ShouldEqual, 2)

		err = basket.Add(NewUsageByPathWithQuantity("/compute/c1/run", big.NewRat(600, 1)))
		So(err, ShouldBeNil)
		So(basket.Length(), ShouldEqual, 3)
	})
}

func TestBasket_Total(t *testing.T) {
	Convey("Testing Basket.Total", t, FailureContinues, func() {
		Convey("3 compute instances", func() {
			basket := NewBasket()
			So(basket, ShouldNotBeNil)
			So(basket.Total(), ShouldEqualBigRat, ratZero)

			err := basket.Add(NewUsageByPathWithQuantity("/compute/c1/run", big.NewRat(1, 1)))
			So(err, ShouldBeNil)
			So(basket.Total(), ShouldEqualBigRat, big.NewRat(72, 100)) // 0.72

			err = basket.Add(NewUsageByPathWithQuantity("/compute/c1/run", big.NewRat(42, 1)))
			So(err, ShouldBeNil)
			So(basket.Total(), ShouldEqualBigRat, big.NewRat(144, 100)) // 1.44

			err = basket.Add(NewUsageByPathWithQuantity("/compute/c1/run", big.NewRat(600, 1)))
			So(err, ShouldBeNil)
			So(basket.Total(), ShouldEqualBigRat, big.NewRat(744, 100)) // 7.44
		})
		Convey("1 compute instance with 2 volumes and 1 ip", func() {
			basket := NewBasket()

			basket.Add(NewUsageByPath("/compute/c1/run"))
			basket.Add(NewUsageByPath("/ip/dynamic"))
			basket.Add(NewUsageByPath("/storage/local/ssd/storage"))
			basket.Add(NewUsageByPath("/storage/local/ssd/storage"))
			So(basket.Length(), ShouldEqual, 4)

			basket.SetDuration(1 * time.Minute)
			So(basket.Total(), ShouldEqualBigRat, big.NewRat(136, 100)) // 1.36

			basket.SetDuration(1 * time.Hour)
			So(basket.Total(), ShouldEqualBigRat, big.NewRat(136, 100)) // 1.36

			basket.SetDuration(2 * time.Hour)
			So(basket.Total(), ShouldEqualBigRat, big.NewRat(232, 100)) // 2.32

			basket.SetDuration(2 * 24 * time.Hour)
			So(basket.Total(), ShouldEqualBigRat, big.NewRat(8399, 1000)) // 8.399

			basket.SetDuration(30 * 24 * time.Hour)
			So(basket.Total(), ShouldEqualBigRat, big.NewRat(11999, 1000)) // 11.999

			// FIXME: this test is false, the capacity is per month
			basket.SetDuration(365 * 24 * time.Hour)
			So(basket.Total(), ShouldEqualBigRat, big.NewRat(11999, 1000)) // 11.999
		})
	})
}
{'fraction_non_alphanumeric': 0.17090777837935392, 'fraction_numerical': 0.048186247969680567, 'mean_word_length': 4.514427860696517, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5158472', 'n_tokens_mistral': 2500, 'n_tokens_neox': 2068, 'n_words': 366}