tests: add nitmetrics test for --detect-covar
authorJean Privat <jean@pryen.org>
Thu, 11 Dec 2014 16:47:24 +0000 (11:47 -0500)
committerJean Privat <jean@pryen.org>
Fri, 12 Dec 2014 16:05:19 +0000 (11:05 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

tests/base_ft_detect_variance_constraints.nit [new file with mode: 0644]
tests/nitmetrics.args
tests/sav/nitmetrics_args1.res
tests/sav/nitmetrics_args2.res [new file with mode: 0644]

diff --git a/tests/base_ft_detect_variance_constraints.nit b/tests/base_ft_detect_variance_constraints.nit
new file mode 100644 (file)
index 0000000..4ab98ed
--- /dev/null
@@ -0,0 +1,96 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# Test classes for variance analysis
+
+import end
+
+interface Object
+end
+
+# covariant
+class A[T]
+       fun foo: T is abstract
+end
+
+# contravariant
+class B[T]
+       fun foo(t: T) is abstract
+end
+
+# invariant
+class C[T]
+       fun foo(t: T) is abstract
+
+       fun bar: T is abstract
+end
+
+# bivariant
+class D[T]
+       fun foo(x: Object) is abstract
+end
+
+# bivariant, the contravariant position of this complex expression
+# reverse the variance, but contra*bivar = bivar
+class E[T]
+       super D[T]
+
+       fun bar(x: E[D[C[T]]]) is abstract
+end
+
+# Covariant, the contravariant position reverse the variance,
+# and the variance of A[B[T]] is contravariance
+class F[T]
+       super D[T]
+
+       fun bar(x: A[B[T]]) is abstract
+end
+
+# Can be annotated bivariant
+class G[T]
+       super D[T]
+
+       fun bar: A[D[E[T]]] is abstract
+end
+
+# invariant
+class H[T]
+       fun bar: A[B[C[T]]] is abstract
+end
+
+# Bivariant
+class Src[T]
+       fun bar (x: Dest[T]) is abstract
+end
+
+# Bivariant
+class Dest[T]
+       fun bar (x: Src[T]) is abstract
+end
+
+# Contravariant
+class Src2[T]
+       super B[T]
+
+       fun bar(x: Src[B[T]]) is abstract
+end
+
+# Bivariant
+class Cycle2[T]
+       fun foo(x: Cycle2[T]): Cycle2[T] is abstract
+end
+
+# Bivariant
+class Cycle3[T]
+       fun foo(x: Cycle2[T]): C[D[T]] is abstract
+end
index c6b8e98..9efd294 100644 (file)
@@ -1 +1,2 @@
 --no-colors --all --csv base_simple3.nit -d $WRITE
+--detect-variance-constraints base_ft_detect_variance_constraints.nit
index e5ac8bd..64216c0 100644 (file)
@@ -440,6 +440,24 @@ Distribution of direct smallers
   intern: 1 (1.81%)
   Object: 1 (1.81%)
   Bool: 1 (1.81%)
+--- Metrics of covariance detection ---
+-- Generic classes --
+ list:
+  non generic: 7 (100.00%)
+  total classes: 7
+  total formal parameters: 0
+-- Including `private` properties --
+  covariants: 0 (na%)
+  contravariants: 0 (na%)
+  bivariants: 0 (na%)
+  invariants: 0 (na%)
+  total: 0
+-- Excluding `private` properties --
+  covariants: 0 (na%)
+  contravariants: 0 (na%)
+  bivariants: 0 (na%)
+  invariants: 0 (na%)
+  total: 0
 --- Metrics of refinement usage ---
 Number of modules: 1
 
diff --git a/tests/sav/nitmetrics_args2.res b/tests/sav/nitmetrics_args2.res
new file mode 100644 (file)
index 0000000..44d7ef9
--- /dev/null
@@ -0,0 +1,20 @@
+*** METRICS ***
+--- Metrics of covariance detection ---
+-- Generic classes --
+ list:
+  with 1 formal type parameter: 13 (92.85%)
+  non generic: 1 (7.14%)
+  total classes: 14
+  total formal parameters: 13
+-- Including `private` properties --
+  covariants: 2 (15.38%)
+  contravariants: 2 (15.38%)
+  bivariants: 7 (53.84%)
+  invariants: 2 (15.38%)
+  total: 13
+-- Excluding `private` properties --
+  covariants: 2 (15.38%)
+  contravariants: 2 (15.38%)
+  bivariants: 7 (53.84%)
+  invariants: 2 (15.38%)
+  total: 13