Skip to content

Commit

Permalink
Move tests; Sourcegraph shows them all being available under async
Browse files Browse the repository at this point in the history
Pretty much, someone could call async.TestParallel() with the way that
it was setup. This will move it outside of async so that they can't run
tests, because no one should need to run them programmatically anyway.
  • Loading branch information
Southern committed Jun 10, 2014
1 parent 9169a40 commit 45eca50
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 56 deletions.
31 changes: 17 additions & 14 deletions filter_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package async
package async_test

import "testing"
import (
"github.com/Southern/async"
"testing"
)

func TestFilterString(t *testing.T) {
str := []string{
Expand All @@ -18,7 +21,7 @@ func TestFilterString(t *testing.T) {
"test5",
}

mapper := func(done Done, args ...interface{}) {
mapper := func(done async.Done, args ...interface{}) {
Status("Hit string")
Status("Args: %+v\n", args)
if args[0] == "test3" {
Expand All @@ -39,7 +42,7 @@ func TestFilterString(t *testing.T) {
}
}

Filter(str, mapper, final)
async.Filter(str, mapper, final)
}

func TestFilterBool(t *testing.T) {
Expand All @@ -58,7 +61,7 @@ func TestFilterBool(t *testing.T) {
false,
}

mapper := func(done Done, args ...interface{}) {
mapper := func(done async.Done, args ...interface{}) {
Status("Hit bool")
Status("Args: %+v\n", args)
if args[1] == 2 {
Expand All @@ -79,7 +82,7 @@ func TestFilterBool(t *testing.T) {
}
}

Filter(bools, mapper, final)
async.Filter(bools, mapper, final)
}

func TestFilterInt(t *testing.T) {
Expand All @@ -98,7 +101,7 @@ func TestFilterInt(t *testing.T) {
5,
}

mapper := func(done Done, args ...interface{}) {
mapper := func(done async.Done, args ...interface{}) {
Status("Hit bool")
Status("Args: %+v\n", args)
if args[0] == 3 {
Expand All @@ -119,7 +122,7 @@ func TestFilterInt(t *testing.T) {
}
}

Filter(bools, mapper, final)
async.Filter(bools, mapper, final)
}

func TestFilterStringParallel(t *testing.T) {
Expand All @@ -138,7 +141,7 @@ func TestFilterStringParallel(t *testing.T) {
"test5",
}

mapper := func(done Done, args ...interface{}) {
mapper := func(done async.Done, args ...interface{}) {
Status("Hit string")
Status("Args: %+v\n", args)
if args[0] == "test3" {
Expand All @@ -159,7 +162,7 @@ func TestFilterStringParallel(t *testing.T) {
}
}

FilterParallel(str, mapper, final)
async.FilterParallel(str, mapper, final)
}

func TestFilterBoolParallel(t *testing.T) {
Expand All @@ -178,7 +181,7 @@ func TestFilterBoolParallel(t *testing.T) {
false,
}

mapper := func(done Done, args ...interface{}) {
mapper := func(done async.Done, args ...interface{}) {
Status("Hit bool")
Status("Args: %+v\n", args)
if args[1] == 2 {
Expand All @@ -199,7 +202,7 @@ func TestFilterBoolParallel(t *testing.T) {
}
}

FilterParallel(bools, mapper, final)
async.FilterParallel(bools, mapper, final)
}

func TestFilterIntParallel(t *testing.T) {
Expand All @@ -218,7 +221,7 @@ func TestFilterIntParallel(t *testing.T) {
5,
}

mapper := func(done Done, args ...interface{}) {
mapper := func(done async.Done, args ...interface{}) {
Status("Hit bool")
Status("Args: %+v\n", args)
if args[0] == 3 {
Expand All @@ -239,5 +242,5 @@ func TestFilterIntParallel(t *testing.T) {
}
}

FilterParallel(bools, mapper, final)
async.FilterParallel(bools, mapper, final)
}
2 changes: 1 addition & 1 deletion helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package async
package async_test

import (
"fmt"
Expand Down
21 changes: 12 additions & 9 deletions list_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package async
package async_test

import "testing"
import (
"github.com/Southern/async"
"testing"
)

func TestAdd(t *testing.T) {
Status("Creating list")
list := New()
list := async.New()

Status("Adding routine")
list.Add(func(done Done, args ...interface{}) {
list.Add(func(done async.Done, args ...interface{}) {
Status("Args: %+v", args)
})

Expand All @@ -18,12 +21,12 @@ func TestAdd(t *testing.T) {

func TestMultiple(t *testing.T) {
Status("Creating list")
list := New()
list := async.New()

Status("Adding multiple routines")
list, _ = list.Multiple(func(done Done, args ...interface{}) {
list, _ = list.Multiple(func(done async.Done, args ...interface{}) {
Status("Args: %+v", args)
}, func(done Done, args ...interface{}) {
}, func(done async.Done, args ...interface{}) {
Status("Args2: %+v", args)
})

Expand All @@ -34,10 +37,10 @@ func TestMultiple(t *testing.T) {

func TestRemove(t *testing.T) {
Status("Creating list")
list := New()
list := async.New()

Status("Adding routine")
list, elem := list.Add(func(done Done, args ...interface{}) {
list, elem := list.Add(func(done async.Done, args ...interface{}) {
Status("Args: %+v", args)
})

Expand Down
31 changes: 17 additions & 14 deletions map_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package async
package async_test

import "testing"
import (
"github.com/Southern/async"
"testing"
)

func TestMapString(t *testing.T) {
str := []string{
Expand All @@ -19,7 +22,7 @@ func TestMapString(t *testing.T) {
"test5",
}

mapper := func(done Done, args ...interface{}) {
mapper := func(done async.Done, args ...interface{}) {
Status("Hit string")
Status("Args: %+v\n", args)
if args[1] == 0 {
Expand All @@ -40,15 +43,15 @@ func TestMapString(t *testing.T) {
}
}

Map(str, mapper, final)
async.Map(str, mapper, final)
}

func TestMapInt(t *testing.T) {
ints := []int{1, 2, 3, 4, 5}

expects := []int{2, 4, 6, 8, 10}

mapper := func(done Done, args ...interface{}) {
mapper := func(done async.Done, args ...interface{}) {
Status("Hit int")
Status("Args: %+v\n", args)
done(nil, args[0].(int)*2)
Expand All @@ -65,15 +68,15 @@ func TestMapInt(t *testing.T) {
}
}

Map(ints, mapper, final)
async.Map(ints, mapper, final)
}

func TestMapBool(t *testing.T) {
bools := []bool{true, false, false, true, false}

expects := []bool{true, true, false, true, false}

mapper := func(done Done, args ...interface{}) {
mapper := func(done async.Done, args ...interface{}) {
Status("Hit bool")
Status("Args: %+v\n", args)
if args[1] == 1 {
Expand All @@ -94,7 +97,7 @@ func TestMapBool(t *testing.T) {
}
}

Map(bools, mapper, final)
async.Map(bools, mapper, final)
}

func TestMapStringParallel(t *testing.T) {
Expand All @@ -114,7 +117,7 @@ func TestMapStringParallel(t *testing.T) {
"test5",
}

mapper := func(done Done, args ...interface{}) {
mapper := func(done async.Done, args ...interface{}) {
Status("Hit string")
Status("Args: %+v\n", args)
if args[1] == 0 {
Expand All @@ -135,15 +138,15 @@ func TestMapStringParallel(t *testing.T) {
}
}

MapParallel(str, mapper, final)
async.MapParallel(str, mapper, final)
}

func TestMapIntParallel(t *testing.T) {
ints := []int{1, 2, 3, 4, 5}

expects := []int{2, 4, 6, 8, 10}

mapper := func(done Done, args ...interface{}) {
mapper := func(done async.Done, args ...interface{}) {
Status("Hit int")
Status("Args: %+v\n", args)
done(nil, args[0].(int)*2)
Expand All @@ -160,15 +163,15 @@ func TestMapIntParallel(t *testing.T) {
}
}

MapParallel(ints, mapper, final)
async.MapParallel(ints, mapper, final)
}

func TestMapBoolParallel(t *testing.T) {
bools := []bool{true, false, false, true, false}

expects := []bool{true, true, false, true, false}

mapper := func(done Done, args ...interface{}) {
mapper := func(done async.Done, args ...interface{}) {
Status("Hit bool")
Status("Args: %+v\n", args)
if args[1] == 1 {
Expand All @@ -189,5 +192,5 @@ func TestMapBoolParallel(t *testing.T) {
}
}

MapParallel(bools, mapper, final)
async.MapParallel(bools, mapper, final)
}
19 changes: 10 additions & 9 deletions parallel_test.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
package async
package async_test

import (
"fmt"
"github.com/Southern/async"
"testing"
"time"
)

func TestParallel(t *testing.T) {
Status("Calling parallel")
Parallel([]Routine{
func(done Done, args ...interface{}) {
async.Parallel([]async.Routine{
func(done async.Done, args ...interface{}) {
Status("First parallel function")
Status("Called with arguments: %+v", args)
done(nil, "arg1", "arg2", "arg3")
},

func(done Done, args ...interface{}) {
func(done async.Done, args ...interface{}) {
Status("Second parallel function")
Status("Called with arguments: %+v", args)
time.Sleep(time.Second)
done(nil, "arg4", "arg5", "arg6")
},

func(done Done, args ...interface{}) {
func(done async.Done, args ...interface{}) {
Status("Third parallel function")
Status("Called with arguments: %+v", args)
done(nil, "arg7", "arg8", "arg9")
Expand All @@ -39,21 +40,21 @@ func TestParallel(t *testing.T) {

func TestParallelError(t *testing.T) {
Status("Calling Parallel")
Parallel([]Routine{
func(done Done, args ...interface{}) {
async.Parallel([]async.Routine{
func(done async.Done, args ...interface{}) {
Status("First parallel function")
Status("Called with arguments: %+v", args)
done(nil, "arg1", "arg2", "arg3")
},

func(done Done, args ...interface{}) {
func(done async.Done, args ...interface{}) {
Status("Second parallel function")
Status("Called with arguments: %+v", args)
time.Sleep(time.Second)
done(fmt.Errorf("Test error"))
},

func(done Done, args ...interface{}) {
func(done async.Done, args ...interface{}) {
Status("Third parallel function")
Status("Called with arguments: %+v", args)
done(nil, "arg4", "arg5", "arg6")
Expand Down

0 comments on commit 45eca50

Please sign in to comment.