Commit 146d3d33 authored by Richer Maximilien's avatar Richer Maximilien

Add test & benchmarks

parent 3fa199f4
Pipeline #345 passed with stage
......@@ -7,13 +7,12 @@ import (
// GenerateSignSequence for the contract signature
//
// The generated sequence is an array of integers refering to the User array.
func GenerateSignSequence(users []entities.User) []int {
return squaredSignEngine(len(users))
func GenerateSignSequence(users []*entities.User) []int {
return SquaredSignEngine(len(users))
}
// squaredSignEngine is a basic ^2 engine for sequence generation
func squaredSignEngine(n int) []int {
// SquaredSignEngine is a basic ^2 engine for sequence generation
func SquaredSignEngine(n int) []int {
sequence := make([]int, n*n)
for i := 0; i < n; i++ {
......@@ -25,8 +24,8 @@ func squaredSignEngine(n int) []int {
return sequence
}
// squaredSignEngineSlice is the same as the above with slicing
func squaredSignEngineSlice(n int) []int {
// SquaredSignEngineSlice is the same as the above with slicing
func SquaredSignEngineSlice(n int) []int {
baseSequence := make([]int, n)
// populate base slice
......
package contract_test
import (
"dfss/dfssp/contract"
"dfss/dfssp/entities"
"github.com/bmizerany/assert"
"testing"
)
var refSeq = []int{0, 1, 2, 0, 1, 2, 0, 1, 2} // for n = 3
func TestGenerateSignSequence(t *testing.T) {
// initialise fixtures
var users = make([]*entities.User, 3)
users[0] = entities.NewUser()
users[1] = entities.NewUser()
users[2] = entities.NewUser()
users[0].Email = "user1@example.com"
users[1].Email = "user2@example.com"
users[2].Email = "user3@example.com"
assert.Equal(t, refSeq, contract.GenerateSignSequence(users))
}
// Perform sequence generation in a loop
func BenchmarkSquaredEngine(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = contract.SquaredSignEngine(10)
}
}
// Perform sequence generation in a loop with slicing
func BenchmarkSquaredEngineSlice(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = contract.SquaredSignEngineSlice(10)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment