Skip to content

Commit

Permalink
move code
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Aug 21, 2022
1 parent d357b1b commit ef67d38
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 80 deletions.
89 changes: 89 additions & 0 deletions pkg/extractor/v9/extractor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package v9

import (
"github.com/alaingilbert/ogame/pkg/ogame"
"github.com/stretchr/testify/assert"
"io/ioutil"
"testing"
"time"
)

func TestExtractResourcesDetailsFromFullPage(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../../samples/v9.0.0/en/overview2.html")
res := NewExtractor().ExtractResourcesDetailsFromFullPage(pageHTMLBytes)
assert.Equal(t, int64(6182), res.Metal.Available)
assert.Equal(t, int64(10060), res.Metal.CurrentProduction)
assert.Equal(t, int64(1590000), res.Metal.StorageCapacity)
assert.Equal(t, int64(84388), res.Crystal.Available)
assert.Equal(t, int64(4989), res.Crystal.CurrentProduction)
assert.Equal(t, int64(1590000), res.Crystal.StorageCapacity)
assert.Equal(t, int64(100188), res.Deuterium.Available)
assert.Equal(t, int64(3499), res.Deuterium.CurrentProduction)
assert.Equal(t, int64(865000), res.Deuterium.StorageCapacity)
assert.Equal(t, int64(-1679), res.Energy.Available)
assert.Equal(t, int64(2690), res.Energy.CurrentProduction)
assert.Equal(t, int64(-4369), res.Energy.Consumption)
assert.Equal(t, int64(8000), res.Darkmatter.Available)
assert.Equal(t, int64(0), res.Darkmatter.Purchased)
assert.Equal(t, int64(8000), res.Darkmatter.Found)
}

func TestExtractResources(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../../samples/v9.0.0/en/overview.html")
res := NewExtractor().ExtractResources(pageHTMLBytes)
assert.Equal(t, int64(10000), res.Metal)
assert.Equal(t, int64(10000), res.Crystal)
assert.Equal(t, int64(7829), res.Deuterium)
assert.Equal(t, int64(26), res.Energy)
assert.Equal(t, int64(10000000), res.Darkmatter)
}

func TestExtractEspionageReport(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../../samples/v9.0.0/en/spy_report.html")
e := NewExtractor()
e.SetLocation(time.FixedZone("OGT", 3600))
infos, err := e.ExtractEspionageReport(pageHTMLBytes)
assert.NoError(t, err)
assert.Equal(t, int64(0), infos.LastActivity)
}

func TestExtractOverviewProduction(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../../samples/v9.0.2/en/lifeform/overview_all_queues.html")
prods, countdown, _ := NewExtractor().ExtractOverviewProduction(pageHTMLBytes)
assert.Equal(t, 4, len(prods))
assert.Equal(t, int64(1660), countdown)
assert.Equal(t, ogame.SmallCargoID, prods[0].ID)
assert.Equal(t, int64(1), prods[0].Nbr)
assert.Equal(t, ogame.SmallCargoID, prods[1].ID)
assert.Equal(t, int64(2), prods[1].Nbr)
assert.Equal(t, ogame.LightFighterID, prods[2].ID)
assert.Equal(t, int64(3), prods[2].Nbr)
assert.Equal(t, ogame.RocketLauncherID, prods[3].ID)
assert.Equal(t, int64(2), prods[3].Nbr)
}

func TestCancelResearch(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../../samples/v9.0.2/en/overview_all_queues.html")
token, id, listID, _ := NewExtractor().ExtractCancelResearchInfos(pageHTMLBytes)
assert.Equal(t, "66f639922a3c76fe6074d12ae36e573e", token)
assert.Equal(t, int64(108), id)
assert.Equal(t, int64(3469490), listID)
}

func TestCancelResearchLF(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../../samples/v9.0.2/en/lifeform/overview_all_queues.html")
e := NewExtractor()
e.SetLifeformEnabled(true)
token, id, listID, _ := e.ExtractCancelResearchInfos(pageHTMLBytes)
assert.Equal(t, "07287218c9661bcc67b05ec1b6171fe8", token)
assert.Equal(t, int64(113), id)
assert.Equal(t, int64(3998106), listID)
}

func TestCancelLfBuildingLF(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../../samples/v9.0.2/en/lifeform/overview_all_queues.html")
token, id, listID, _ := NewExtractor().ExtractCancelLfBuildingInfos(pageHTMLBytes)
assert.Equal(t, "07287218c9661bcc67b05ec1b6171fe8", token)
assert.Equal(t, int64(11101), id)
assert.Equal(t, int64(3998104), listID)
}
80 changes: 0 additions & 80 deletions pkg/wrapper/ogame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,6 @@ func TestExtractResources(t *testing.T) {
assert.Equal(t, int64(25000), res.Darkmatter)
}

func TestExtractResourcesV9(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../samples/v9.0.0/en/overview.html")
res := v9.NewExtractor().ExtractResources(pageHTMLBytes)
assert.Equal(t, int64(10000), res.Metal)
assert.Equal(t, int64(10000), res.Crystal)
assert.Equal(t, int64(7829), res.Deuterium)
assert.Equal(t, int64(26), res.Energy)
assert.Equal(t, int64(10000000), res.Darkmatter)
}

func TestExtractResourcesMobile(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../samples/unversioned/preferences_mobile.html")
res := v6.NewExtractor().ExtractResources(pageHTMLBytes)
Expand Down Expand Up @@ -202,26 +192,6 @@ func TestExtractResourcesDetailsFromFullPage(t *testing.T) {
assert.Equal(t, int64(25000), res.Darkmatter.Found)
}

func TestExtractResourcesDetailsFromFullPageV9(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../samples/v9.0.0/en/overview2.html")
res := v9.NewExtractor().ExtractResourcesDetailsFromFullPage(pageHTMLBytes)
assert.Equal(t, int64(6182), res.Metal.Available)
assert.Equal(t, int64(10060), res.Metal.CurrentProduction)
assert.Equal(t, int64(1590000), res.Metal.StorageCapacity)
assert.Equal(t, int64(84388), res.Crystal.Available)
assert.Equal(t, int64(4989), res.Crystal.CurrentProduction)
assert.Equal(t, int64(1590000), res.Crystal.StorageCapacity)
assert.Equal(t, int64(100188), res.Deuterium.Available)
assert.Equal(t, int64(3499), res.Deuterium.CurrentProduction)
assert.Equal(t, int64(865000), res.Deuterium.StorageCapacity)
assert.Equal(t, int64(-1679), res.Energy.Available)
assert.Equal(t, int64(2690), res.Energy.CurrentProduction)
assert.Equal(t, int64(-4369), res.Energy.Consumption)
assert.Equal(t, int64(8000), res.Darkmatter.Available)
assert.Equal(t, int64(0), res.Darkmatter.Purchased)
assert.Equal(t, int64(8000), res.Darkmatter.Found)
}

func TestExtractResourcesDetailsFromFullPageV7(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../samples/v7/overview2.html")
res := v6.NewExtractor().ExtractResourcesDetailsFromFullPage(pageHTMLBytes)
Expand Down Expand Up @@ -2174,32 +2144,6 @@ func TestCancelBuildingV902(t *testing.T) {
assert.Equal(t, int64(3469488), listID)
}

func TestCancelLfBuildingLFV902(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../samples/v9.0.2/en/lifeform/overview_all_queues.html")
token, id, listID, _ := v9.NewExtractor().ExtractCancelLfBuildingInfos(pageHTMLBytes)
assert.Equal(t, "07287218c9661bcc67b05ec1b6171fe8", token)
assert.Equal(t, int64(11101), id)
assert.Equal(t, int64(3998104), listID)
}

func TestCancelResearchV902(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../samples/v9.0.2/en/overview_all_queues.html")
token, id, listID, _ := v9.NewExtractor().ExtractCancelResearchInfos(pageHTMLBytes)
assert.Equal(t, "66f639922a3c76fe6074d12ae36e573e", token)
assert.Equal(t, int64(108), id)
assert.Equal(t, int64(3469490), listID)
}

func TestCancelResearchLFV902(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../samples/v9.0.2/en/lifeform/overview_all_queues.html")
e := v9.NewExtractor()
e.SetLifeformEnabled(true)
token, id, listID, _ := e.ExtractCancelResearchInfos(pageHTMLBytes)
assert.Equal(t, "07287218c9661bcc67b05ec1b6171fe8", token)
assert.Equal(t, int64(113), id)
assert.Equal(t, int64(3998106), listID)
}

func TestCancelResearch(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../samples/unversioned/overview_active_queue2.html")
token, techID, listID, _ := v6.NewExtractor().ExtractCancelResearchInfos(pageHTMLBytes)
Expand Down Expand Up @@ -2501,21 +2445,6 @@ func TestV71ExtractOverviewProduction(t *testing.T) {
assert.Equal(t, int64(3), prods[3].Nbr)
}

func TestV902ExtractOverviewProduction(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../samples/v9.0.2/en/lifeform/overview_all_queues.html")
prods, countdown, _ := v9.NewExtractor().ExtractOverviewProduction(pageHTMLBytes)
assert.Equal(t, 4, len(prods))
assert.Equal(t, int64(1660), countdown)
assert.Equal(t, ogame.SmallCargoID, prods[0].ID)
assert.Equal(t, int64(1), prods[0].Nbr)
assert.Equal(t, ogame.SmallCargoID, prods[1].ID)
assert.Equal(t, int64(2), prods[1].Nbr)
assert.Equal(t, ogame.LightFighterID, prods[2].ID)
assert.Equal(t, int64(3), prods[2].Nbr)
assert.Equal(t, ogame.RocketLauncherID, prods[3].ID)
assert.Equal(t, int64(2), prods[3].Nbr)
}

func TestExtractV71Production(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../samples/v7.1/en/shipyard_queue.html")
prods, secs, _ := v71.NewExtractor().ExtractProduction(pageHTMLBytes)
Expand Down Expand Up @@ -2727,15 +2656,6 @@ func TestExtractEspionageReportV8(t *testing.T) {
assert.Equal(t, int64(15), infos.LastActivity)
}

func TestExtractEspionageReportV9(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../samples/v9.0.0/en/spy_report.html")
e := v9.NewExtractor()
e.SetLocation(time.FixedZone("OGT", 3600))
infos, err := e.ExtractEspionageReport(pageHTMLBytes)
assert.NoError(t, err)
assert.Equal(t, int64(0), infos.LastActivity)
}

func TestExtractEspionageReportAllianceClass(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../samples/v8.1/en/spy_report_alliance_class_trader.html")
e := v71.NewExtractor()
Expand Down

0 comments on commit ef67d38

Please sign in to comment.