Skip to content

Commit

Permalink
Adding tests and code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
aylanonsense committed Mar 19, 2019
1 parent 83c4882 commit 9594d1f
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 467 deletions.
6 changes: 6 additions & 0 deletions .busted
@@ -0,0 +1,6 @@
return {
default = {
coverage = true,
pattern = '.lua'
}
}
5 changes: 5 additions & 0 deletions .gitignore
@@ -0,0 +1,5 @@
# Silly Mac files
.DS_Store

# Code coverage files
luacov.*
15 changes: 15 additions & 0 deletions README.md
@@ -1,2 +1,17 @@
# simulsim
Another attempt at a multiplayer framework.

## Tests
simulsim uses [busted](https://olivinelabs.com/busted/) for running tests, [LuaCOv](https://keplerproject.github.io/luacov/) for code coverage, and [Luacov-console](https://github.com/spacewander/luacov-console) for code coverage visualization.

To get started, install all of the dependencies above using [LuaRocks](https://luarocks.org/):
luarocks install busted
luarocks install luacov
luarocks install luacov-console

To run the unit tests:
busted ./tests

To get a code coverage report:
luacov && luacov-console && luacov-console -s

91 changes: 0 additions & 91 deletions src/Connection.lua

This file was deleted.

208 changes: 0 additions & 208 deletions src/Server.lua

This file was deleted.

@@ -1,5 +1,5 @@
-- Load dependencies
local TransportLayer = require 'src/singlePlayer/TransportLayer'
local TransportLayer = require 'src/fauxNetwork/TransportLayer'

local Connection = {}
function Connection:new(params)
Expand Down
File renamed without changes.
Expand Up @@ -72,4 +72,9 @@ function TransportLayer:updateAll(dt)
end
end

-- Clears out the array of tranport layers being tracked
function TransportLayer:removeAll()
transportLayers = {}
end

return TransportLayer
45 changes: 45 additions & 0 deletions src/fauxNetwork/createFauxNetwork.lua
@@ -0,0 +1,45 @@
-- Load dependencies
local TransportLayer = require 'src/fauxNetwork/TransportLayer'
local Connection = require 'src/fauxNetwork/Connection'
local Server = require 'src/fauxNetwork/Server'

-- Creates a fake, in-memory network of clients and servers
return function(params)
local numClients = params and params.numClients or 1
local transportLayerParams = {
latency = params and params.latency,
latencyDeviation = params and params.latencyDeviation,
packetLossChance = params and params.packetLossChance
}

-- Create the server
local server = Server:new()

-- Create the clients
local clients = {}
for i = 1, numClients do
-- Create the transport layers
local clientToServer = TransportLayer:new(transportLayerParams)
local serverToClient = TransportLayer:new(transportLayerParams)

-- Create the server connection
local serverConn = Connection:new({
isClient = false,
sendTransportLayer = serverToClient,
receiveTransportLayer = clientToServer
})
serverConn:onConnect(function()
server:handleConnect(serverConn)
end)

-- Create the client connection
table.insert(clients, Connection:new({
isClient = true,
sendTransportLayer = clientToServer,
receiveTransportLayer = serverToClient
}))
end

-- Return them
return server, clients
end

0 comments on commit 9594d1f

Please sign in to comment.