diff --git a/engine/libsuppliers_test.go b/engine/libsuppliers_test.go index 74af9779c..8560ea113 100644 --- a/engine/libsuppliers_test.go +++ b/engine/libsuppliers_test.go @@ -26,7 +26,6 @@ import ( func TestLibSuppliersSortCost(t *testing.T) { sSpls := &SortedSuppliers{ - Sorting: utils.MetaLeastCost, SortedSuppliers: []*SortedSupplier{ &SortedSupplier{ SupplierID: "supplier1", @@ -56,7 +55,6 @@ func TestLibSuppliersSortCost(t *testing.T) { } sSpls.SortLeastCost() eOrderedSpls := &SortedSuppliers{ - Sorting: utils.MetaLeastCost, SortedSuppliers: []*SortedSupplier{ &SortedSupplier{ SupplierID: "supplier3", @@ -223,7 +221,6 @@ func TestSortedSuppliersDigest3(t *testing.T) { func TestLibSuppliersSortHighestCost(t *testing.T) { sSpls := &SortedSuppliers{ - Sorting: utils.MetaHighestCost, SortedSuppliers: []*SortedSupplier{ &SortedSupplier{ SupplierID: "supplier1", @@ -253,7 +250,6 @@ func TestLibSuppliersSortHighestCost(t *testing.T) { } sSpls.SortHighestCost() eOrderedSpls := &SortedSuppliers{ - Sorting: utils.MetaHighestCost, SortedSuppliers: []*SortedSupplier{ &SortedSupplier{ SupplierID: "supplier2", @@ -286,3 +282,68 @@ func TestLibSuppliersSortHighestCost(t *testing.T) { utils.ToJSON(eOrderedSpls), utils.ToJSON(sSpls)) } } + +func TestLibSuppliersSortQOS(t *testing.T) { + sSpls := &SortedSuppliers{ + SortedSuppliers: []*SortedSupplier{ + &SortedSupplier{ + SupplierID: "supplier1", + SortingData: map[string]interface{}{ + utils.MetaACD: 0.1, + utils.MetaTCD: 15.0, + }, + SupplierParameters: "param1", + }, + &SortedSupplier{ + SupplierID: "supplier2", + SortingData: map[string]interface{}{ + utils.MetaACD: 0.2, + utils.MetaTCD: 20.0, + }, + SupplierParameters: "param2", + }, + &SortedSupplier{ + SupplierID: "supplier3", + SortingData: map[string]interface{}{ + utils.MetaACD: 0.05, + utils.MetaTCD: 10.0, + }, + SupplierParameters: "param3", + }, + }, + } + sSpls.SortQOS() + eOrderedSpls := &SortedSuppliers{ + SortedSuppliers: []*SortedSupplier{ + &SortedSupplier{ + SupplierID: "supplier3", + SortingData: map[string]interface{}{ + utils.MetaACD: 0.05, + utils.MetaTCD: 10.0, + }, + SupplierParameters: "param3", + }, + + &SortedSupplier{ + SupplierID: "supplier2", + SortingData: map[string]interface{}{ + utils.MetaACD: 0.2, + utils.MetaTCD: 20.0, + }, + SupplierParameters: "param2", + }, + &SortedSupplier{ + SupplierID: "supplier1", + SortingData: map[string]interface{}{ + utils.MetaACD: 0.1, + utils.MetaTCD: 15.0, + }, + SupplierParameters: "param1", + }, + }, + } + if !reflect.DeepEqual(eOrderedSpls, sSpls) { + t.Errorf("Expecting: %s, received: %s", + utils.ToJSON(eOrderedSpls), utils.ToJSON(sSpls)) + } +} diff --git a/engine/spls_highestcost.go b/engine/spls_highestcost.go index a44aa1edf..c2f5bc767 100755 --- a/engine/spls_highestcost.go +++ b/engine/spls_highestcost.go @@ -66,10 +66,11 @@ func (lcs *HightCostSorter) SortSuppliers(prflID string, suppls []*Supplier, for k, v := range costData { srtData[k] = v } - sortedSuppls.SortedSuppliers = append(sortedSuppls.SortedSuppliers, &SortedSupplier{ - SupplierID: s.ID, - SortingData: srtData, - SupplierParameters: s.SupplierParameters}) + sortedSuppls.SortedSuppliers = append(sortedSuppls.SortedSuppliers, + &SortedSupplier{ + SupplierID: s.ID, + SortingData: srtData, + SupplierParameters: s.SupplierParameters}) } if len(sortedSuppls.SortedSuppliers) == 0 { return nil, utils.ErrNotFound diff --git a/engine/spls_leastcost.go b/engine/spls_leastcost.go index 23ef67183..94c5cca78 100644 --- a/engine/spls_leastcost.go +++ b/engine/spls_leastcost.go @@ -66,10 +66,11 @@ func (lcs *LeastCostSorter) SortSuppliers(prflID string, suppls []*Supplier, for k, v := range costData { srtData[k] = v } - sortedSuppls.SortedSuppliers = append(sortedSuppls.SortedSuppliers, &SortedSupplier{ - SupplierID: s.ID, - SortingData: srtData, - SupplierParameters: s.SupplierParameters}) + sortedSuppls.SortedSuppliers = append(sortedSuppls.SortedSuppliers, + &SortedSupplier{ + SupplierID: s.ID, + SortingData: srtData, + SupplierParameters: s.SupplierParameters}) } if len(sortedSuppls.SortedSuppliers) == 0 { return nil, utils.ErrNotFound diff --git a/engine/spls_qos.go b/engine/spls_qos.go index 6a485342c..fd5d6c2a4 100755 --- a/engine/spls_qos.go +++ b/engine/spls_qos.go @@ -60,10 +60,11 @@ func (lcs *QOSSupplierSorter) SortSuppliers(prflID string, suppls []*Supplier, srtData[k] = v } - sortedSuppls.SortedSuppliers = append(sortedSuppls.SortedSuppliers, &SortedSupplier{ - SupplierID: s.ID, - SortingData: srtData, - SupplierParameters: s.SupplierParameters}) + sortedSuppls.SortedSuppliers = append(sortedSuppls.SortedSuppliers, + &SortedSupplier{ + SupplierID: s.ID, + SortingData: srtData, + SupplierParameters: s.SupplierParameters}) } if len(sortedSuppls.SortedSuppliers) == 0 { return nil, utils.ErrNotFound