forked from craftlion/communautofinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
communautofinder_test.go
47 lines (34 loc) · 1.47 KB
/
communautofinder_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package communautofinder
import (
"context"
"fmt"
"testing"
"time"
)
func TestUseExemple(t *testing.T) {
const cityId = 59 // see available cities -> https://restapifrontoffice.reservauto.net/ReservautoFrontOffice/index.html?urls.primaryName=Branch%20version%202%20(6.93.1)#/
var currentCoordinate Coordinate = New(45.538638, -73.570039)
startDate := time.Now().AddDate(0, 0, 13)
endDate := time.Now().AddDate(0, 0, 14)
// Search flex car
nbCarFoundFlex := SearchFlexCar(cityId, currentCoordinate, 10)
fmt.Printf("Flex cars found : %d \n", nbCarFoundFlex)
// Search station car
nbCarFoundStation := SearchStationCar(cityId, currentCoordinate, 10, startDate, endDate)
fmt.Printf("Station cars found : %d \n", nbCarFoundStation)
/////////////////////////////////
var resultsChannelStation = make(chan int, 1)
var resultsChannelFlex = make(chan int, 1)
defer close(resultsChannelStation)
defer close(resultsChannelFlex)
ctx, cancel := context.WithCancel(context.Background())
// Search flex car with go routine
go SearchFlexCarForGoRoutine(cityId, currentCoordinate, 10, resultsChannelFlex, ctx, cancel)
nbCarFoundFlex = <-resultsChannelFlex
fmt.Printf("Flex cars found : %d \n", nbCarFoundFlex)
// Search station car with go routine
go SearchStationCarForGoRoutine(cityId, currentCoordinate, 10, startDate, endDate, resultsChannelStation, ctx, cancel)
nbCarFoundStation = <-resultsChannelStation
fmt.Printf("Station cars found : %d \n", nbCarFoundStation)
cancel()
}