Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Aug 21, 2022
1 parent 973fcc8 commit 0db8a7a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 37 deletions.
11 changes: 11 additions & 0 deletions pkg/extractor/v7/extractor_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v7

import (
"github.com/alaingilbert/clockwork"
"github.com/alaingilbert/ogame/pkg/ogame"
"github.com/stretchr/testify/assert"
"io/ioutil"
Expand Down Expand Up @@ -308,3 +309,13 @@ func TestExtractFleetSlot_FleetDispatch(t *testing.T) {
assert.Equal(t, int64(0), s.ExpInUse)
assert.Equal(t, int64(1), s.ExpTotal)
}

func TestGetConstructionsV7(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../../samples/v7/overview_supplies_in_construction.html")
clock := clockwork.NewFakeClockAt(time.Date(2019, 11, 12, 9, 6, 43, 0, time.UTC))
buildingID, buildingCountdown, researchID, researchCountdown := ExtractConstructions(pageHTMLBytes, clock)
assert.Equal(t, ogame.MetalMineID, buildingID)
assert.Equal(t, int64(62), buildingCountdown)
assert.Equal(t, ogame.EnergyTechnologyID, researchID)
assert.Equal(t, int64(271), researchCountdown)
}
25 changes: 25 additions & 0 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
package utils

import (
"bytes"
"github.com/PuerkitoBio/goquery"
"github.com/stretchr/testify/assert"
"io/ioutil"
"regexp"
"testing"
)

func TestParseInt(t *testing.T) {
assert.Equal(t, int64(1234567890), ParseInt("1.234.567.890"))
}

func TestParseInt2(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../samples/unversioned/deathstar_price.html")
doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(pageHTMLBytes))
title := doc.Find("li.metal").AttrOr("title", "")
metalStr := regexp.MustCompile(`([\d.]+)`).FindStringSubmatch(title)[1]
metal := ParseInt(metalStr)
assert.Equal(t, int64(5000000), metal)

pageHTMLBytes, _ = ioutil.ReadFile("../../samples/unversioned/mrd_price.html")
doc, _ = goquery.NewDocumentFromReader(bytes.NewReader(pageHTMLBytes))
title = doc.Find("li.metal").AttrOr("title", "")
metalStr = regexp.MustCompile(`([\d.]+)`).FindStringSubmatch(title)[1]
metal = ParseInt(metalStr)
assert.Equal(t, int64(1555733200), metal)
}

func TestToInt(t *testing.T) {
assert.Equal(t, 1234567890, ToInt([]byte("1234567890")))
}

func TestMinInt(t *testing.T) {
assert.Equal(t, int64(2), MinInt(5, 2, 3))
}

func TestI64Ptr(t *testing.T) {
v := int64(6)
assert.Equal(t, &v, I64Ptr(6))
}
39 changes: 2 additions & 37 deletions pkg/wrapper/ogame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ package wrapper

import (
"bytes"
"github.com/alaingilbert/ogame/pkg/extractor/v7"
"github.com/PuerkitoBio/goquery"
"github.com/alaingilbert/ogame/pkg/ogame"
"github.com/alaingilbert/ogame/pkg/utils"
"github.com/hashicorp/go-version"
"github.com/stretchr/testify/assert"
"io/ioutil"
"regexp"
"testing"
"time"

"github.com/PuerkitoBio/goquery"
"github.com/alaingilbert/clockwork"
"github.com/stretchr/testify/assert"
)

func BenchmarkUserInfoRegex(b *testing.B) {
Expand Down Expand Up @@ -47,22 +43,6 @@ func TestWrapper(t *testing.T) {
assert.NotNil(t, bot)
}

func TestParseInt2(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../samples/unversioned/deathstar_price.html")
doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(pageHTMLBytes))
title := doc.Find("li.metal").AttrOr("title", "")
metalStr := regexp.MustCompile(`([\d.]+)`).FindStringSubmatch(title)[1]
metal := utils.ParseInt(metalStr)
assert.Equal(t, int64(5000000), metal)

pageHTMLBytes, _ = ioutil.ReadFile("../../samples/unversioned/mrd_price.html")
doc, _ = goquery.NewDocumentFromReader(bytes.NewReader(pageHTMLBytes))
title = doc.Find("li.metal").AttrOr("title", "")
metalStr = regexp.MustCompile(`([\d.]+)`).FindStringSubmatch(title)[1]
metal = utils.ParseInt(metalStr)
assert.Equal(t, int64(1555733200), metal)
}

//func TestGetResourcesProductionsLight(t *testing.T) {
// supplies := ResourcesBuildings{
// MetalMine: 32,
Expand Down Expand Up @@ -131,27 +111,12 @@ func TestExtractCargoCapacity(t *testing.T) {
// assert.Equal(t, 49, infos.Position(5).Activity)
//}

func TestGetConstructionsV7(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../samples/v7/overview_supplies_in_construction.html")
clock := clockwork.NewFakeClockAt(time.Date(2019, 11, 12, 9, 6, 43, 0, time.UTC))
buildingID, buildingCountdown, researchID, researchCountdown := v7.ExtractConstructions(pageHTMLBytes, clock)
assert.Equal(t, ogame.MetalMineID, buildingID)
assert.Equal(t, int64(62), buildingCountdown)
assert.Equal(t, ogame.EnergyTechnologyID, researchID)
assert.Equal(t, int64(271), researchCountdown)
}

func TestExtractFleetsFromEventList(t *testing.T) {
//pageHTMLBytes, _ := ioutil.ReadFile("../../samples/eventlist_test.html")
//fleets := NewExtractor().ExtractFleetsFromEventList(pageHTMLBytes)
//assert.Equal(t, 4, len(fleets))
}

func TestI64Ptr(t *testing.T) {
v := int64(6)
assert.Equal(t, &v, utils.I64Ptr(6))
}

func TestGalaxyDistance(t *testing.T) {
assert.Equal(t, int64(60000), galaxyDistance(6, 3, 6, false))
assert.Equal(t, int64(20000), galaxyDistance(1, 2, 6, false))
Expand Down

0 comments on commit 0db8a7a

Please sign in to comment.