浏览代码

add more tests

/main
Xingwei Zhu 3 年前
当前提交
7381f6c6
共有 2 个文件被更改,包括 62 次插入2 次删除
  1. 62
      Samples/UIWidgetsSamples_2019_4/Assets/Editor/Tests/Stream/TestMain.cs
  2. 2
      com.unity.uiwidgets/Runtime/async/stream.cs

62
Samples/UIWidgetsSamples_2019_4/Assets/Editor/Tests/Stream/TestMain.cs


Debug.Log("sum = " + (int)val);
});
}
/**
* Test subscription.pause/resume/cancel
*/
private void test8()
{
Stream<int> numbers = Stream<int>.periodic(new TimeSpan(0, 0, 0, 1), t => t).take(3);
var subscription = numbers.listen(n =>
{
Debug.Log("num = " + n);
}, onDone: () =>
{
Debug.Log("periodic finished");
});
Future.delayed(new TimeSpan(0, 0, 0, 0, 1200), () =>
{
Debug.Log("pause >>>>");
subscription.pause();
return FutureOr.nil;
}).then(v =>
{
Future.delayed(new TimeSpan(0, 0, 0, 5), () =>
{
Debug.Log("resume >>>>");
subscription.resume();
return FutureOr.nil;
}).then(v2 =>
{
Future.delayed(new TimeSpan(0, 0, 0, 1), () =>
{
Debug.Log("cancel >>>>");
subscription.cancel();
return FutureOr.nil;
});
});
});
}
/**
* Test Stream.map, distinct
*/
private void test9()
{
string convert(int number)
{
return "string " + number;
}
bool stringEqual(string s1, string s2)
{
return s1 == s2;
}
Stream<string> numbers = Stream<int>.fromIterable(new List<int> {0, 1, 2, 2, 3, 4, 5, 5}).map(convert).distinct(stringEqual);
numbers.listen(val =>
{
Debug.Log("val = " + val);
});
}
test7();
test9();
return new Container();
}
}

2
com.unity.uiwidgets/Runtime/async/stream.cs


return new _SkipWhileStream<T>(this, d => test(d));
}
Stream<T> distinct(Func<T, T, bool> equals) {
public Stream<T> distinct(Func<T, T, bool> equals) {
return new _DistinctStream<T>(this, (d1, d2) => equals(d1, d2));
}

正在加载...
取消
保存