Commit 36308c41 authored by Boris Mühmer's avatar Boris Mühmer
Browse files

Merge branch 'development-0.1.1' of repositories.muehmer.net:bsmrgo/playground...

Merge branch 'development-0.1.1' of repositories.muehmer.net:bsmrgo/playground into development-0.1.1
parents 08a8f0b0 d4a5428f
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
package concurrency

// Sequence ...
type Sequence chan int

// SequenceOf returns a stream of numbers of the supplied value.
func SequenceOf(v int) Sequence {
	i := make(Sequence)

	go func(x int, r Sequence) {
		for {
			r <- x
		}
	}(v, i)

	return i
}

// Take ...
func (s Sequence) Take(c int) []int {
	r := []int{}

	for x := range s {
		r = append(r, x)
	}

	return r
}
+25 −0
Original line number Diff line number Diff line
package concurrency

import (
	"reflect"
	"testing"
)

func TestAnything(t *testing.T) {
}

func TestBasic(t *testing.T) {
	done := make(chan bool)
	go func(done chan bool) {
		t.Log("Hello from goroutine.")
		done <- true
	}(done)
	<-done
	t.Log("goroutine is done.")
}

func TestSequence(t *testing.T) {

	l0 := []int{1, 1, 1, 1, 1}
	if r := SequenceOf(1).Take(5); reflect.DeepEqual(r, l0) {
		t.Errorf("SequenceOf(1).Take(5) is %v, expected %v", r, l0)

	}

	//for _, tv := range []struct {
	//
	//}

}