Skip to content

Commit

Permalink
updated tests with new slices
Browse files Browse the repository at this point in the history
  • Loading branch information
lologarithm committed Oct 2, 2023
1 parent 9b33828 commit d7d6280
Show file tree
Hide file tree
Showing 42 changed files with 2,992 additions and 2,997 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.21

require (
github.com/google/go-cmp v0.5.8
github.com/google/uuid v1.3.1
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
github.com/satori/go.uuid v1.2.0
github.com/spf13/cobra v1.7.0
github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a
golang.org/x/exp v0.0.0-20221028150844-83b7d23a625f
Expand All @@ -16,5 +16,4 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.1.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
16 changes: 2 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
Expand All @@ -30,12 +23,7 @@ golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
3 changes: 1 addition & 2 deletions sim/core/attack.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package core

import (
"slices"
"time"

"golang.org/x/exp/slices"

"github.com/wowsims/wotlk/sim/core/proto"
"github.com/wowsims/wotlk/sim/core/stats"
)
Expand Down
13 changes: 10 additions & 3 deletions sim/core/buffs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package core

import (
"math"
"slices"
"strconv"
"time"

"golang.org/x/exp/slices"
googleProto "google.golang.org/protobuf/proto"

"github.com/wowsims/wotlk/sim/core/proto"
Expand Down Expand Up @@ -1307,8 +1307,15 @@ func (raid *Raid) ProcReplenishment(sim *Simulation, src ReplenishmentSource) {
}

eligible := append(raid.curReplenishmentUnits[src], raid.leftoverReplenishmentUnits...)
slices.SortFunc(eligible, func(v1, v2 *Unit) bool {
return v1.CurrentManaPercent() < v2.CurrentManaPercent()
slices.SortFunc(eligible, func(v1, v2 *Unit) int {
v1Mana := v1.CurrentManaPercent()
v2Mana := v2.CurrentManaPercent()
if v1Mana > v2Mana {
return 1
} else if v2Mana > v1Mana {
return -1
}
return 0
})
raid.curReplenishmentUnits[src] = eligible[:10]
raid.leftoverReplenishmentUnits = eligible[10:]
Expand Down
12 changes: 2 additions & 10 deletions sim/core/bulksim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/wowsims/wotlk/sim/core/proto"
goproto "google.golang.org/protobuf/proto"
"google.golang.org/protobuf/encoding/protojson"
)

const (
Expand Down Expand Up @@ -107,15 +107,7 @@ func TestBulkSim(t *testing.T) {

want := &proto.BulkSimResult{}
if diff := cmp.Diff(want, got, cmp.Comparer(func(a, b *proto.BulkSimResult) bool {
am, err := goproto.Marshal(a)
if err != nil {
return false
}
bm, err := goproto.Marshal(b)
if err != nil {
return false
}
return string(am) == string(bm)
return protojson.Format(a) == protojson.Format(b)
})); diff != "" {
t.Fatalf("BulkSim() returned diff (-want +got):\n%s", diff)
}
Expand Down
2 changes: 1 addition & 1 deletion sim/core/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"time"

"golang.org/x/exp/slices"
"slices"

"github.com/wowsims/wotlk/sim/core/proto"
"github.com/wowsims/wotlk/sim/core/stats"
Expand Down
7 changes: 4 additions & 3 deletions sim/core/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package core
import (
"time"

"slices"

"github.com/wowsims/wotlk/sim/core/proto"
"golang.org/x/exp/slices"
)

type EnvironmentState int
Expand Down Expand Up @@ -180,8 +181,8 @@ func (env *Environment) finalize(raidProto *proto.Raid, _ *proto.Encounter, raid
}
env.postFinalizeEffects = nil

slices.SortStableFunc(env.prepullActions, func(a1, a2 PrepullAction) bool {
return a1.DoAt < a2.DoAt
slices.SortStableFunc(env.prepullActions, func(a1, a2 PrepullAction) int {
return int(a1.DoAt - a2.DoAt)
})

env.setupAttackTables()
Expand Down
2 changes: 1 addition & 1 deletion sim/core/item_effects.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package core

import (
"fmt"
"golang.org/x/exp/slices"
"slices"
"strconv"
"time"

Expand Down
6 changes: 3 additions & 3 deletions sim/core/item_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package core

import (
"fmt"
"golang.org/x/exp/slices"
"slices"
)

type ItemSet struct {
Expand All @@ -27,8 +27,8 @@ func (set ItemSet) Items() []Item {
}
}
// Sort so the order of IDs is always consistent, for tests.
slices.SortFunc(items, func(a, b Item) bool {
return a.ID < b.ID
slices.SortFunc(items, func(a, b Item) int {
return int(a.ID - b.ID)
})
return items
}
Expand Down
9 changes: 6 additions & 3 deletions sim/core/major_cooldown.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package core
import (
"time"

"golang.org/x/exp/slices"
"slices"

"github.com/wowsims/wotlk/sim/core/proto"
"github.com/wowsims/wotlk/sim/core/stats"
Expand Down Expand Up @@ -507,9 +507,12 @@ func (mcdm *majorCooldownManager) UpdateMajorCooldowns() {
}

func (mcdm *majorCooldownManager) sort() {
slices.SortStableFunc(mcdm.majorCooldowns, func(m1, m2 *MajorCooldown) bool {
slices.SortStableFunc(mcdm.majorCooldowns, func(m1, m2 *MajorCooldown) int {
// Since we're just comparing and don't actually care about the remaining CD, ok to use 0 instead of sim.CurrentTime.
return m1.ReadyAt() < m2.ReadyAt() || (m1.ReadyAt() == m2.ReadyAt() && m1.Priority > m2.Priority)
if m1.ReadyAt() != m2.ReadyAt() {
return int(m1.ReadyAt() - m2.ReadyAt())
}
return int(m1.Priority - m2.Priority)
})
}

Expand Down
5 changes: 3 additions & 2 deletions sim/core/pet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package core

import (
"fmt"
"slices"
"time"

"github.com/wowsims/wotlk/sim/core/proto"
"github.com/wowsims/wotlk/sim/core/stats"
"golang.org/x/exp/slices"
"time"
)

// Extension of Agent interface, for Pets.
Expand Down
11 changes: 6 additions & 5 deletions sim/core/raid.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package core

import (
"slices"

"github.com/wowsims/wotlk/sim/core/proto"
"github.com/wowsims/wotlk/sim/core/stats"
"golang.org/x/exp/slices"
googleProto "google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -306,11 +307,11 @@ func (raid *Raid) updatePlayersAndPets() {
raid.AllUnits = append(raidPlayers, raidPets...)
raid.AllPlayerUnits = raidPlayers

slices.SortFunc(raid.AllUnits, func(u1, u2 *Unit) bool {
return u1.Index < u2.Index
slices.SortFunc(raid.AllUnits, func(u1, u2 *Unit) int {
return int(u1.Index - u2.Index)
})
slices.SortFunc(raid.AllPlayerUnits, func(u1, u2 *Unit) bool {
return u1.Index < u2.Index
slices.SortFunc(raid.AllPlayerUnits, func(u1, u2 *Unit) int {
return int(u1.Index - u2.Index)
})
}

Expand Down
8 changes: 4 additions & 4 deletions sim/core/runic_power.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ type RuneChangeType int32

const (
None RuneChangeType = 0
SpendRune = 1
GainRune = 2
ConvertToDeath = 4
ConvertFromDeath = 8
SpendRune RuneChangeType = 1
GainRune RuneChangeType = 2
ConvertToDeath RuneChangeType = 4
ConvertFromDeath RuneChangeType = 8
)

func (r RuneChangeType) Matches(other RuneChangeType) bool {
Expand Down
2 changes: 1 addition & 1 deletion sim/core/test_generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

"golang.org/x/exp/slices"
"slices"

"github.com/wowsims/wotlk/sim/core/proto"
googleProto "google.golang.org/protobuf/proto"
Expand Down
Loading

0 comments on commit d7d6280

Please sign in to comment.