2021-05-20 18:03:45 +02:00
package main
import (
"fmt"
"testing"
)
func TestRangeFilter ( t * testing . T ) {
tests := [ ] struct {
feat: add price range filter (#26)
To avoid scalpers' price, the bot now understand filters on prices
using a minimum and maximum value, in a currency and a pattern to
detect the model.
Example:
```
"price_ranges": [
{"model": "3090", "max": 3000, "currency": "EUR"},
{"model": "3080", "max": 1600, "currency": "EUR"},
{"model": "3070", "max": 1200, "currency": "EUR"}
],
```
More details in README.md.
Signed-off-by: Julien Riou <julien@riou.xyz>
2021-05-23 02:32:30 +02:00
product * Product
2021-05-20 18:03:45 +02:00
model string // model regex to apply on the product name
min float64 // minimum price
max float64 // maximum price
feat: add price range filter (#26)
To avoid scalpers' price, the bot now understand filters on prices
using a minimum and maximum value, in a currency and a pattern to
detect the model.
Example:
```
"price_ranges": [
{"model": "3090", "max": 3000, "currency": "EUR"},
{"model": "3080", "max": 1600, "currency": "EUR"},
{"model": "3070", "max": 1200, "currency": "EUR"}
],
```
More details in README.md.
Signed-off-by: Julien Riou <julien@riou.xyz>
2021-05-23 02:32:30 +02:00
currency string // price currency
2021-05-20 18:03:45 +02:00
included bool // should be included or not
} {
feat: add price range filter (#26)
To avoid scalpers' price, the bot now understand filters on prices
using a minimum and maximum value, in a currency and a pattern to
detect the model.
Example:
```
"price_ranges": [
{"model": "3090", "max": 3000, "currency": "EUR"},
{"model": "3080", "max": 1600, "currency": "EUR"},
{"model": "3070", "max": 1200, "currency": "EUR"}
],
```
More details in README.md.
Signed-off-by: Julien Riou <julien@riou.xyz>
2021-05-23 02:32:30 +02:00
{ & Product { Name : "MSI GeForce RTX 3090 GAMING X" , Price : 99.99 , PriceCurrency : "EUR" } , "3090" , 50.0 , 100.0 , "EUR" , true } , // model match and price is in the range, should be included
{ & Product { Name : "MSI GeForce RTX 3090 GAMING X" , Price : 99.99 , PriceCurrency : "EUR" } , "3080" , 50.0 , 100.0 , "EUR" , true } , // model doesn't match, should be included
{ & Product { Name : "MSI GeForce RTX 3090 GAMING X" , Price : 999.99 , PriceCurrency : "EUR" } , "3090" , 50.0 , 100.0 , "EUR" , false } , // model match and price is outside of the range, shoud not be included
{ & Product { Name : "MSI GeForce RTX 3090 GAMING X" , Price : 99.99 , PriceCurrency : "EUR" } , "" , 50.0 , 100.0 , "EUR" , true } , // model regex is missing, should be included
{ & Product { Name : "MSI GeForce RTX 3090 GAMING X" , Price : 99.99 , PriceCurrency : "EUR" } , "3090" , 50.0 , 0.0 , "EUR" , true } , // upper limit is missing, should be included
2021-05-20 18:03:45 +02:00
}
feat: add price range filter (#26)
To avoid scalpers' price, the bot now understand filters on prices
using a minimum and maximum value, in a currency and a pattern to
detect the model.
Example:
```
"price_ranges": [
{"model": "3090", "max": 3000, "currency": "EUR"},
{"model": "3080", "max": 1600, "currency": "EUR"},
{"model": "3070", "max": 1200, "currency": "EUR"}
],
```
More details in README.md.
Signed-off-by: Julien Riou <julien@riou.xyz>
2021-05-23 02:32:30 +02:00
converter := NewCurrencyConverter ( )
2021-05-20 18:03:45 +02:00
for i , tc := range tests {
t . Run ( fmt . Sprintf ( "TestRangeFilter#%d" , i ) , func ( t * testing . T ) {
feat: add price range filter (#26)
To avoid scalpers' price, the bot now understand filters on prices
using a minimum and maximum value, in a currency and a pattern to
detect the model.
Example:
```
"price_ranges": [
{"model": "3090", "max": 3000, "currency": "EUR"},
{"model": "3080", "max": 1600, "currency": "EUR"},
{"model": "3070", "max": 1200, "currency": "EUR"}
],
```
More details in README.md.
Signed-off-by: Julien Riou <julien@riou.xyz>
2021-05-23 02:32:30 +02:00
filter , err := NewRangeFilter ( tc . model , tc . min , tc . max , tc . currency , converter )
2021-05-20 18:03:45 +02:00
if err != nil {
t . Errorf ( "cannot create filter with model regex '%s' and price range [%.2f, %.2f]: %s" , tc . model , tc . min , tc . max , err )
}
feat: add price range filter (#26)
To avoid scalpers' price, the bot now understand filters on prices
using a minimum and maximum value, in a currency and a pattern to
detect the model.
Example:
```
"price_ranges": [
{"model": "3090", "max": 3000, "currency": "EUR"},
{"model": "3080", "max": 1600, "currency": "EUR"},
{"model": "3070", "max": 1200, "currency": "EUR"}
],
```
More details in README.md.
Signed-off-by: Julien Riou <julien@riou.xyz>
2021-05-23 02:32:30 +02:00
included := filter . Include ( tc . product )
2021-05-20 18:03:45 +02:00
if included != tc . included {
feat: add price range filter (#26)
To avoid scalpers' price, the bot now understand filters on prices
using a minimum and maximum value, in a currency and a pattern to
detect the model.
Example:
```
"price_ranges": [
{"model": "3090", "max": 3000, "currency": "EUR"},
{"model": "3080", "max": 1600, "currency": "EUR"},
{"model": "3070", "max": 1200, "currency": "EUR"}
],
```
More details in README.md.
Signed-off-by: Julien Riou <julien@riou.xyz>
2021-05-23 02:32:30 +02:00
t . Errorf ( "product '%s' of price %.2f%s with model regex '%s' and range [%.2f, %.2f]: got included=%t, want included=%t" , tc . product . Name , tc . product . Price , tc . product . PriceCurrency , tc . model , tc . min , tc . max , included , tc . included )
2021-05-20 18:03:45 +02:00
} else {
if included {
feat: add price range filter (#26)
To avoid scalpers' price, the bot now understand filters on prices
using a minimum and maximum value, in a currency and a pattern to
detect the model.
Example:
```
"price_ranges": [
{"model": "3090", "max": 3000, "currency": "EUR"},
{"model": "3080", "max": 1600, "currency": "EUR"},
{"model": "3070", "max": 1200, "currency": "EUR"}
],
```
More details in README.md.
Signed-off-by: Julien Riou <julien@riou.xyz>
2021-05-23 02:32:30 +02:00
t . Logf ( "product '%s' included by model regex '%s' and range [%.2f, %.2f]" , tc . product . Name , tc . model , tc . min , tc . max )
2021-05-20 18:03:45 +02:00
} else {
feat: add price range filter (#26)
To avoid scalpers' price, the bot now understand filters on prices
using a minimum and maximum value, in a currency and a pattern to
detect the model.
Example:
```
"price_ranges": [
{"model": "3090", "max": 3000, "currency": "EUR"},
{"model": "3080", "max": 1600, "currency": "EUR"},
{"model": "3070", "max": 1200, "currency": "EUR"}
],
```
More details in README.md.
Signed-off-by: Julien Riou <julien@riou.xyz>
2021-05-23 02:32:30 +02:00
t . Logf ( "product '%s' excluded by model regex '%s' and range [%.2f, %.2f]" , tc . product . Name , tc . model , tc . min , tc . max )
2021-05-20 18:03:45 +02:00
}
}
} )
}
}