diff test/testLazyTensors.jl @ 371:241bd2512c20 feature/lazy_function

Add a LazyFunctionArray that evaluates a function for each index.
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 30 Sep 2020 19:48:17 +0200
parents 7fe43d902a27
children 8414c2334393 895ec483d741
line wrap: on
line diff
--- a/test/testLazyTensors.jl	Mon Sep 28 22:56:54 2020 +0200
+++ b/test/testLazyTensors.jl	Wed Sep 30 19:48:17 2020 +0200
@@ -193,4 +193,23 @@
     @test_throws DimensionMismatch v1 + v2
 end
 
+@testset "LazyFunctionArray" begin
+    @test LazyFunctionArray(i->i^2, (3,)) == [1,4,9]
+    @test LazyFunctionArray((i,j)->i*j, (3,2)) == [
+        1 2;
+        2 4;
+        3 6;
+    ]
+
+    @test size(LazyFunctionArray(i->i^2, (3,))) == (3,)
+    @test size(LazyFunctionArray((i,j)->i*j, (3,2))) == (3,2)
+
+    @inferred LazyFunctionArray(i->i^2, (3,))[2]
+
+    @test_throws BoundsError LazyFunctionArray(i->i^2, (3,))[4]
+    @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[4,2]
+    @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[2,3]
+
 end
+
+end