package utils import ( "testing" ) func Test_toMoney(t *testing.T) { type args struct { priceString string } tests := []struct { name string args args want int }{ { "should just remove special characters", args{ priceString: "$765,000", }, 765000, }, { "$1.5m", args{ priceString: "$1.5m", }, 1500000, }, { "$390k", args{ priceString: "$390k", }, 390000, }, { "$2.01m max bid", args{ priceString: `$2.01m max bid`, }, 2010000, }, { `$890k max bid`, args{ priceString: `$890k max bid`, }, 890000, }, { "empty string", args{ priceString: "", }, 0, }, { "Price withheld", args{ priceString: "Price withheld", }, -1, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := ToMoney(tt.args.priceString); got != tt.want { t.Errorf("toMoney() = %v, want %v", got, tt.want) } }) } } func Test_toBed(t *testing.T) { type args struct { bedsString string } tests := []struct { name string args args want int }{ { "2 beds", args{ "2 beds", }, 2, }, { "1 bed", args{ "1 bed", }, 1, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := ToBeds(tt.args.bedsString); got != tt.want { t.Errorf("toBed() = %v, want %v", got, tt.want) } }) } } func TestPercentStringToFloat(t *testing.T) { type args struct { percent string } tests := []struct { name string args args want float64 }{ { "76%", args{ percent: "76%", }, float64(76), }, { "76.66%", args{ percent: "76.66%", }, float64(76.66), }, { "6.78%", args{ percent: "6.78%", }, float64(6.78), }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := PercentStringToFloat(tt.args.percent); got != tt.want { t.Errorf("PercentStringToFloat() = %v, want %v", got, tt.want) } }) } }