-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from MattSScott/server-rename-and-testing
Server package rename and testing
- Loading branch information
Showing
11 changed files
with
187 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package baseagent_test | ||
|
||
import ( | ||
"testing" | ||
|
||
baseagent "github.com/MattSScott/basePlatformSOMAS/pkg/main/BaseAgent" | ||
"github.com/google/uuid" | ||
) | ||
|
||
type IBaseAgent interface { | ||
baseagent.IAgent[IBaseAgent] | ||
} | ||
|
||
func TestAgentIdOperations(t *testing.T) { | ||
baseAgent := baseagent.NewAgent[IBaseAgent]() | ||
|
||
if baseAgent.GetID() == uuid.Nil { | ||
t.Error("Agent not instantiated with valid ID") | ||
} | ||
} | ||
|
||
type AgentWithState struct { | ||
*baseagent.BaseAgent[*AgentWithState] | ||
state int | ||
} | ||
|
||
func (aws *AgentWithState) UpdateAgentInternalState() { | ||
aws.state += 1 | ||
} | ||
|
||
func TestUpdateAgentInternalState(t *testing.T) { | ||
ag := AgentWithState{ | ||
baseagent.NewAgent[*AgentWithState](), | ||
0, | ||
} | ||
|
||
if ag.state != 0 { | ||
t.Error("Additional agent field not correctly instantiated") | ||
} | ||
|
||
ag.UpdateAgentInternalState() | ||
|
||
if ag.state != 1 { | ||
t.Error("Agent state not correctly updated") | ||
} | ||
} | ||
|
||
func TestMessageRetrieval(t *testing.T) { | ||
|
||
agent := baseagent.NewAgent[IBaseAgent]() | ||
|
||
messages := agent.GetAllMessages([]IBaseAgent{agent}) | ||
|
||
if len(messages) > 0 { | ||
t.Error("Agent erroneously constructed message") | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
pkg/main/server/baseServer.go → pkg/main/BaseServer/baseServer.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package server | ||
package baseserver | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package baseserver_test | ||
|
||
import ( | ||
"testing" | ||
|
||
baseagent "github.com/MattSScott/basePlatformSOMAS/pkg/main/BaseAgent" | ||
baseserver "github.com/MattSScott/basePlatformSOMAS/pkg/main/BaseServer" | ||
) | ||
|
||
type ITestBaseAgent interface { | ||
baseagent.IAgent[ITestBaseAgent] | ||
} | ||
|
||
type TestBaseAgent struct { | ||
*baseagent.BaseAgent[ITestBaseAgent] | ||
} | ||
|
||
func NewTestBaseAgent() ITestBaseAgent { | ||
return &TestBaseAgent{ | ||
baseagent.NewAgent[ITestBaseAgent](), | ||
} | ||
} | ||
|
||
func TestAgentsCorrectlyInstantiated(t *testing.T) { | ||
m := make([]baseserver.AgentGeneratorCountPair[ITestBaseAgent], 1) | ||
m[0] = baseserver.MakeAgentGeneratorCountPair[ITestBaseAgent](NewTestBaseAgent, 3) | ||
|
||
server := baseserver.CreateServer[ITestBaseAgent](m, 1) | ||
|
||
if len(server.GetAgents()) != 3 { | ||
t.Error("Incorrect number of agents added to server") | ||
} | ||
|
||
} | ||
|
||
func TestNumTurnsInServer(t *testing.T) { | ||
m := make([]baseserver.AgentGeneratorCountPair[ITestBaseAgent], 1) | ||
m[0] = baseserver.MakeAgentGeneratorCountPair[ITestBaseAgent](NewTestBaseAgent, 3) | ||
|
||
server := baseserver.CreateServer[ITestBaseAgent](m, 1) | ||
|
||
if server.GetNumTurns() != 1 { | ||
t.Error("Incorrect number of turns instantiated") | ||
} | ||
|
||
} | ||
|
||
type IExtendedTestServer interface { | ||
baseserver.IServer[ITestBaseAgent] | ||
GetAdditionalField() int | ||
} | ||
|
||
type ExtendedTestServer struct { | ||
*baseserver.BaseServer[ITestBaseAgent] | ||
testField int | ||
} | ||
|
||
func (ets *ExtendedTestServer) GetAdditionalField() int { | ||
return ets.testField | ||
} | ||
|
||
func (ets *ExtendedTestServer) RunGameLoop() { | ||
|
||
ets.BaseServer.RunGameLoop() | ||
ets.testField += 1 | ||
} | ||
|
||
func CreateTestServer(mapper []baseserver.AgentGeneratorCountPair[ITestBaseAgent], iters int) IExtendedTestServer { | ||
return &ExtendedTestServer{ | ||
BaseServer: baseserver.CreateServer[ITestBaseAgent](mapper, iters), | ||
testField: 0, | ||
} | ||
} | ||
|
||
func TestServerGameLoop(t *testing.T) { | ||
m := make([]baseserver.AgentGeneratorCountPair[ITestBaseAgent], 1) | ||
m[0] = baseserver.MakeAgentGeneratorCountPair[ITestBaseAgent](NewTestBaseAgent, 3) | ||
|
||
server := CreateTestServer(m, 1) | ||
|
||
if server.GetAdditionalField() != 0 { | ||
t.Error("Additional server parameter not correctly instantiated") | ||
} | ||
|
||
server.RunGameLoop() | ||
|
||
if server.GetAdditionalField() != 1 { | ||
t.Error("Run Game Loop method not successfully overridden") | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
pkg/main/server/serverInterface.go → pkg/main/BaseServer/serverInterface.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package server | ||
package baseserver | ||
|
||
import baseagent "github.com/MattSScott/basePlatformSOMAS/pkg/main/BaseAgent" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters