8000 1. fixed bug in asyn-apply with using 'Future' without full name in m… · rssh/scala-gopher@1c8dc9f · GitHub
[go: up one dir, main page]

Skip to content

Commit 1c8dc9f

Browse files
committed
1. fixed bug in asyn-apply with using 'Future' without full name in macro.
2. more tests now async
1 parent 7ee387f commit 1c8dc9f

File tree

3 files changed

+54
-52
lines changed

3 files changed

+54
-52
lines changed

src/main/scala/gopher/goasync/AsyncApply.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ object AsyncApply
7979

8080
def createAsyncParam[A:c.WeakTypeTag,B:c.WeakTypeTag](c:Context)(fp:c.Tree):(c.TermName,c.Tree) =
8181
{
82+
//TODO: add ability to change future system.
8283
import c.universe._
8384
// TODO: check that fp is ident and get fp as name.
8485
val nname = TermName(c.freshName())
85-
val paramType = tq"Function[${c.weakTypeOf[A]},Future[${c.weakTypeOf[B]}]]"
86+
val paramType = tq"Function[${c.weakTypeOf[A]},scala.concurrent.Future[${c.weakTypeOf[B]}]]"
8687
(nname,ValDef(Modifiers(Flag.PARAM),nname,paramType,EmptyTree))
8788
}
8889

src/test/scala/gopher/channels/FoldSelectSuite.scala

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,35 @@ package gopher.channels
22

33

44
import gopher._
5-
import gopher.channels._
6-
import gopher.tags._
7-
85
import org.scalatest._
96

107
import scala.language._
11-
import scala.concurrent._
12-
import scala.concurrent.duration._
13-
148

15-
class FoldSelectSuite extends FunSuite
9+
class FoldSelectSuite extends AsyncFunSuite
1610
{
1711

18-
lazy val gopherApi = CommonTestObjects.gopherApi
19-
import gopherApi._
12+
lazy val gopherApi = CommonTestObjects.gopherApi
13+
import gopherApi._
2014

21-
import scala.concurrent.ExecutionContext.Implicits.global
2215

23-
test("fold-over-selector with changed read") {
24-
//for(i <- 1 to 10000) {
16+
test("fold-over-selector with changed read") {
2517
val in = makeChannel[Int]()
2618
val out = makeChannel[Int]()
2719
var r0 = IndexedSeq[Int]()
2820
val generator = go {
2921
select.fold(in){ (ch,s) =>
3022
s match {
3123
case p:ch.read =>
32-
r0 = r0 :+ p
33-
out.write(p)
34-
ch.filter{ _ % p != 0 }
24+
r0 = r0 :+ p
25+
out.write(p)
26+
ch.filter{ _ % p != 0 }
3527
}
3628
}
3729
}
3830
generator.failed.foreach{ _.printStackTrace() }
39-
//in.awriteAll(2 to Int.MaxValue)
4031
go {
4132
for(i <- 2 to Int.MaxValue) {
42-
in.write(i)
33+
in.write(i)
4334
}
4435
}
4536

@@ -50,24 +41,12 @@ class FoldSelectSuite extends FunSuite
5041
}
5142
}
5243

53-
//val read = scala.async.Async.async(scala.async.Async.await((1 to 100).mapAsync(i=>out.aread)))
54-
//val read = (1 to 100).mapAsync(i=>out.aread)
44+
read map (r => assert(r(18)===67 && r.last === 541) )
45+
46+
}
5547

56-
//val r = Await.result(read,1 second)
57-
val r = Await.result(read,5 seconds)
58-
if (r.last != 541 || r(18)!=67 ) {
59-
System.err.println(s"r0=$r0")
60-
System.err.println(s"r1=$r")
61-
}
62-
//assert(r.last === 29)
63-
//assert(r(0) === 2)
64-
//assert(r(2) === 3)
65-
assert(r(18) === 67)
66-
assert(r.last === 541)
67-
//}
68-
}
6948

70-
test("fold-over-selector with swap read") {
49+
test("fold-over-selector with swap read") {
7150

7251
val in1 = makeChannel[Int]()
7352
val in2 = makeChannel[Int]()
@@ -77,26 +56,27 @@ class FoldSelectSuite extends FunSuite
7756
select.fold((in1,in2,0)){ case ((in1,in2,n),s) =>
7857
s match {
7958
case x:in1.read =>
80-
if (x >= 100) {
81-
select.exit((in1, in2, n))
82-
} else {
83-
(in2, in1, n + x)
84-
}
59+
if (x >= 100) {
60+
select.exit((in1, in2, n))
61+
} else {
62+
(in2, in1, n + x)
63+
}
8564
case x:in2.read =>
86-
(in2,in1,n-x)
65+
(in2,in1,n-x)
8766
}
8867
}
8968
}
9069

91-
9270
in1.awriteAll(1 to 101)
9371

94-
val r = Await.result(generator, 1 second)
72+
//val r = Await.result(generator, 1 second)
9573

9674
// 0 + 1 - 2 + 3 - 4 + 5 - 6 ... +99 - 100 + 101
9775
// - 1 2 -2 3 - 3 +50 - 50
98-
assert(r._3 == - 50)
76+
generator.map(r => assert(r._3 == -50))
9977

100-
}
78+
}
10179

10280
}
81+
82+

src/test/scala/gopher/channels/InputOpsSuite.scala

Lines changed: 29 additions & 8 deletions
45DE
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,42 @@
11
package gopher.channels
22

33
import gopher._
4-
import gopher.channels._
5-
import gopher.tags._
6-
import scala.language._
4+
import org.scalatest._
5+
import org.scalatest.concurrent._
6+
77
import scala.concurrent._
88
import scala.concurrent.duration._
9+
import scala.language._
910
import scala.util._
1011

11-
import org.scalatest._
12-
import org.scalatest.concurrent._
12+
class InputOpsAsyncSuite extends AsyncFunSuite {
1313

14-
import scala.concurrent.ExecutionContext.Implicits.global
1514

16-
class InputOpsSuite extends FunSuite with Waiters {
15+
test("map operation for input") {
16+
val ch = gopherApi.makeChannel[String]()
17+
ch.awriteAll(List("AAA","123","1234","12345"))
18+
val mappedCh = ch map (_.reverse)
19+
mappedCh.atake(4) map { l =>
20+
assert(l(0) == "AAA" &&
21+
l(1) == "321" &&
22+
l(2) == "4321" &&
23+
l(3) == "54321")
24+
}
25+
}
26+
27+
28+
29+
def gopherApi = CommonTestObjects.gopherApi
30+
31+
32+
}
33+
34+
35+
class InputOpsSyncSuite extends FunSuite with Waiters {
36+
37+
import scala.concurrent.ExecutionContext.Implicits.global
38+
1739

18-
1940
test("map operation for input") {
2041
val w = new Waiter
2142
val ch = gopherApi.makeChannel[String]()

0 commit comments

Comments
 (0)
0