Skip to content

Commit

Permalink
test: Add TestIsCheaperOrOlder unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
bgins committed Jan 27, 2025
1 parent 64805d3 commit 9e85474
Showing 1 changed file with 72 additions and 1 deletion.
73 changes: 72 additions & 1 deletion pkg/solver/matcher/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

package matcher

import "testing"
import (
"testing"

"github.com/lilypad-tech/lilypad/pkg/data"
)

func TestMatchOffers(t *testing.T) {
testCases := getMatchTestCases()
Expand All @@ -16,3 +19,71 @@ func TestMatchOffers(t *testing.T) {
})
}
}

func TestIsCheaperOrOlder(t *testing.T) {
testCases := []struct {
name string
offerA data.ResourceOffer
offerB data.ResourceOffer
expected bool
}{
{
name: "cheaper wins",
offerA: data.ResourceOffer{
CreatedAt: 2,
DefaultPricing: data.DealPricing{
InstructionPrice: 100,
},
},
offerB: data.ResourceOffer{
CreatedAt: 1,
DefaultPricing: data.DealPricing{
InstructionPrice: 200,
},
},
expected: true,
},
{
name: "older wins when same price",
offerA: data.ResourceOffer{
CreatedAt: 1,
DefaultPricing: data.DealPricing{
InstructionPrice: 100,
},
},
offerB: data.ResourceOffer{
CreatedAt: 2,
DefaultPricing: data.DealPricing{
InstructionPrice: 100,
},
},
expected: true,
},
{
name: "more expensive loses regardless of age",
offerA: data.ResourceOffer{
CreatedAt: 1,
DefaultPricing: data.DealPricing{
InstructionPrice: 200,
},
},
offerB: data.ResourceOffer{
CreatedAt: 2,
DefaultPricing: data.DealPricing{
InstructionPrice: 100,
},
},
expected: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := isCheaperOrOlder(tc.offerA, tc.offerB)
if result != tc.expected {
t.Errorf("isCheaperOrOlder(%+v, %+v) = %v, expected %v",
tc.offerA, tc.offerB, result, tc.expected)
}
})
}
}

0 comments on commit 9e85474

Please sign in to comment.