More READ negative tests.
[pspp] / tests / language / stats / matrix.at
index 00e4dfdbe02979a20c530a58ef6d6064d64f8552..8f1dba5d7f7d950958091a4e5a5229a6d9f1240a 100644 (file)
@@ -1122,6 +1122,9 @@ PRINT {-1:-3:-1}.
 PRINT {-1:-10:-2}.
 PRINT {-1:-11:-2}.
 
+PRINT {1:1}.
+PRINT {1:1:-1}.
+
 PRINT {1:3:0}.
 PRINT {-1:-3:0}.
 
@@ -1152,14 +1155,20 @@ AT_CHECK([pspp matrix.sps], [1], [dnl
 {-1:-11:-2}
   -1  -3  -5  -7  -9 -11
 
-matrix.sps:12: error: MATRIX: The increment operand to : must be nonzero.
+{1:1}
+  1
+
+{1:1:-1}
+  1
 
-matrix.sps:13: error: MATRIX: The increment operand to : must be nonzero.
+matrix.sps:15: error: MATRIX: The increment operand to : must be nonzero.
 
-matrix.sps:15: error: MATRIX: All rows in a matrix must have the same number of
+matrix.sps:16: error: MATRIX: The increment operand to : must be nonzero.
+
+matrix.sps:18: error: MATRIX: All rows in a matrix must have the same number of
 columns, but this tries to stack matrices with 2 and 1 columns.
 
-matrix.sps:16: error: MATRIX: All columns in a matrix must have the same number
+matrix.sps:19: error: MATRIX: All columns in a matrix must have the same number
 of rows, but this tries to paste matrices with 2 and 1 rows.
 ])
 AT_CLEANUP
@@ -1398,7 +1407,7 @@ dsort
   1.00  3.00
 
 matrix.sps:22: error: MATRIX: GSCH requires its argument to have at least as
-many columns as rows, but it has dimensions (2,1).
+many columns as rows, but it has dimensions 2×1.
 
 matrix.sps:23: error: MATRIX: 2×3 argument to GSCH contains only 0 linearly
 independent columns.
@@ -1422,6 +1431,7 @@ PRINT KRONEKER({1, 2; 3, 4}, {0, 5; 6, 7}).
 PRINT LG10({1, 10, 100, 1000}).
 
 PRINT LN({1, 2; 3, 4})/FORMAT F5.2.
+PRINT LN(0).
 END MATRIX.
 ])
 AT_CHECK([pspp matrix.sps], [0], [dnl
@@ -1469,6 +1479,9 @@ LG10({1, 10, 100, 1000})
 LN({1, 2; 3, 4})
    .00   .69
   1.10  1.39
+
+LN(0)
+ -In
 ])
 AT_CLEANUP
 
@@ -1691,12 +1704,12 @@ AT_CLEANUP
 AT_SETUP([MATRIX - RESHAPE RMAX RMIN RND RNKORDER])
 AT_DATA([matrix.sps], [dnl
 MATRIX.
-PRINT RESHAPE({1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12}, 1, 12).
-PRINT RESHAPE({1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12}, 2, 6).
-PRINT RESHAPE({1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12}, 3, 4).
-PRINT RESHAPE({1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12}, 4, 3).
-PRINT RESHAPE({1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12}, 6, 2).
-PRINT RESHAPE({1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12}, 12, 1).
+PRINT RESHAPE(1:12, 1, 12).
+PRINT RESHAPE(1:12, 2, 6).
+PRINT RESHAPE(1:12, 3, 4).
+PRINT RESHAPE(1:12, 4, 3).
+PRINT RESHAPE(1:12, 6, 2).
+PRINT RESHAPE(1:12, 12, 1).
 
 PRINT RMAX({1, 0, 1; -2, -3, 1; 3, 3, 0}).
 
@@ -1711,25 +1724,25 @@ PRINT RNKORDER({1, 0, 3; 3, 1, 2; 3, 0, 5}) /FORMAT F5.1.
 END MATRIX.
 ])
 AT_CHECK([pspp matrix.sps], [0], [dnl
-RESHAPE({1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12}, 1, 12)
+RESHAPE(1:12, 1, 12)
    1   2   3   4   5   6   7   8   9  10  11  12
 
-RESHAPE({1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12}, 2, 6)
+RESHAPE(1:12, 2, 6)
    1   2   3   4   5   6
    7   8   9  10  11  12
 
-RESHAPE({1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12}, 3, 4)
+RESHAPE(1:12, 3, 4)
    1   2   3   4
    5   6   7   8
    9  10  11  12
 
-RESHAPE({1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12}, 4, 3)
+RESHAPE(1:12, 4, 3)
    1   2   3
    4   5   6
    7   8   9
   10  11  12
 
-RESHAPE({1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12}, 6, 2)
+RESHAPE(1:12, 6, 2)
    1   2
    3   4
    5   6
@@ -1737,7 +1750,7 @@ RESHAPE({1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12}, 6, 2)
    9  10
   11  12
 
-RESHAPE({1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12}, 12, 1)
+RESHAPE(1:12, 12, 1)
    1
    2
    3
@@ -1823,8 +1836,7 @@ SOLVE({2, 1, -1; -3, -1, 2; -2, 1, 2}, {8; -11; -3})
   -1.00
 
 matrix.sps:10: error: MATRIX: SOLVE requires its arguments to have the same
-number of rows, but the first argument has dimensions (2,2) and the second
-(1,2).
+number of rows, but the first argument has dimensions 2×2 and the second 1×2.
 
 SQRT({0, 1, 2, 3, 4, 9, 81})
    .00  1.00  1.41  1.73  2.00  3.00  9.00
@@ -1856,6 +1868,11 @@ PRINT SWEEP(SWEEP(SWEEP(s0, 1), 2), 3)/FORMAT F5.2.
 COMPUTE s1 = {6, 12, 0, 12; 12, 0, 0, 25; 0, 0, 6, 2; 12, 25, 2, 28}.
 PRINT SWEEP(s1, 2).
 
+COMPUTE s2 = {0, 1, 2; 3, 4, 5; 6, 7, 8}.
+PRINT SWEEP(s2, 1).
+PRINT SWEEP(s2, 2).
+PRINT SWEEP(s2, 3).
+
 PRINT TRACE(s0).
 
 PRINT T(s0).
@@ -1920,6 +1937,21 @@ SWEEP(s1, 2)
    0   0   6   2
   12   0   2  28
 
+SWEEP(s2, 1)
+  0  0  0
+  0  4  5
+  0  7  8
+
+SWEEP(s2, 2)
+  -.7500000000  -.2500000000   .7500000000
+   .7500000000   .2500000000  1.2500000000
+   .7500000000 -1.7500000000  -.7500000000
+
+SWEEP(s2, 3)
+ -1.5000000000  -.7500000000  -.2500000000
+  -.7500000000  -.3750000000  -.6250000000
+   .7500000000   .8750000000   .1250000000
+
 TRACE(s0)
   68
 
@@ -2030,9 +2062,9 @@ CALL EIGEN({1, 0; 0, 1}, evec, eval).
 PRINT evec.
 PRINT eval.
 
-CALL EIGEN({3, 2, 4; 2, 0, 2; 4, 2, 3}, evec, eval).
-PRINT evec.
-PRINT eval.
+CALL EIGEN({3, 2, 4; 2, 0, 2; 4, 2, 3}, evec2, eval2).
+PRINT evec2.
+PRINT eval2.
 END MATRIX.
 ])
 AT_CHECK([pspp matrix.sps], [0], [dnl
@@ -2044,12 +2076,12 @@ eval
   1
   1
 
-evec
+evec2
   -.6666666667   .0000000000   .7453559925
   -.3333333333  -.8944271910  -.2981423970
   -.6666666667   .4472135955  -.5962847940
 
-eval
+eval2
   8.0000000000
  -1.0000000000
  -1.0000000000
@@ -2487,6 +2519,10 @@ AT_CLEANUP
 
 AT_SETUP([MATRIX - READ])
 AT_DATA([matrix.txt], [dnl
+9
+8
+7
+6
 1 2 3
 4 5 6
 7 8 9
@@ -2508,6 +2544,8 @@ AT_DATA([matrix2.txt], [dnl
 ])
 AT_DATA([matrix.sps], [dnl
 MATRIX.
+READ x/FILE='matrix.txt'/SIZE=4/FIELD=1 TO 1.
+PRINT x.
 READ x/FILE='matrix.txt'/SIZE={3,3}/FIELD=1 TO 80.
 PRINT x.
 READ x/SIZE={2,4}/FIELD=1 TO 80.
@@ -2529,6 +2567,12 @@ PRINT y.
 END MATRIX.
 ])
 AT_CHECK([pspp matrix.sps], [0], [dnl
+x
+  9
+  8
+  7
+  6
+
 x
   1  2  3
   4  5  6
   41  43  47  53
 ])
 AT_CLEANUP
+
+AT_SETUP([MATRIX - READ - negative])
+AT_DATA([matrix.sps], [dnl
+MATRIX.
+READ !.
+READ x/FILE=!.
+READ x/ENCODING=!.
+READ x/FIELD=!.
+READ x/FIELD=1 !.
+READ x/FIELD=1 TO !.
+READ x/FIELD=1 TO 0.
+READ x/FIELD=1 TO 10 BY !.
+READ x/FIELD=1 TO 10 BY 6.
+READ x/SIZE=!.
+READ x/MODE=!.
+READ x/FORMAT=!.
+READ x/FORMAT=F8.2/FORMAT=F8.2.
+READ x/FORMAT='5XYZZY'.
+READ x/FORMAT=XYZZY.
+READ x/!.
+READ x.
+READ x/FIELD=1 TO 10.
+READ x/FIELD=1 TO 10/SIZE={1,2}.
+READ x/FIELD=1 TO 10/SIZE={1,2}/FILE='xyzzy.txt'/FORMAT='15F'.
+READ x/FIELD=1 TO 10 BY 2/SIZE={1,2}/FILE='xyzzy.txt'/FORMAT=F5.
+READ x/FIELD=1 TO 10 BY 2/SIZE={1,2}/FILE='xyzzy.txt'/FORMAT='2F'.
+READ x/FIELD=1 TO 10/SIZE={1,2;3,4}/FILE='matrix.txt'.
+READ x/FIELD=1 TO 10/SIZE={1,2,3}/FILE='matrix.txt'.
+READ x/FIELD=1 TO 10/SIZE={-1}/FILE='matrix.txt'.
+COMPUTE x={1,2,3}.
+READ x(:,:)/FIELD=1 TO 10/SIZE={2,2}/FILE='matrix.txt'.
+READ x/FIELD=1 TO 10/SIZE={1,3}/FILE='matrix.txt'/MODE=SYMMETRIC.
+END MATRIX.
+])
+AT_DATA([matrix.txt], [])
+AT_CHECK([pspp matrix.sps], [1], [dnl
+matrix.sps:2.6: error: READ: Syntax error at `!': expecting identifier.
+
+matrix.sps:3.13: error: READ: Syntax error at `!': expecting a file name or
+handle name.
+
+matrix.sps:4.17: error: READ: Syntax error at `!': expecting string.
+
+matrix.sps:5.14: error: READ: Syntax error at `!': Expected positive integer
+for FIELD.
+
+matrix.sps:6.16: error: READ: Syntax error at `!': expecting `TO'.
+
+matrix.sps:7.19: error: READ: Syntax error at `!': Expected positive integer
+for TO.
+
+matrix.sps:8.19: error: READ: Syntax error at `0': Expected positive integer
+for TO.
+
+matrix.sps:9.25: error: READ: Syntax error at `!': Expected integer between 1
+and 10 for BY.
+
+matrix.sps:10: error: READ: BY 6 does not evenly divide record width 10.
+
+matrix.sps:11.13: error: READ: Syntax error at `!'.
+
+matrix.sps:12.13: error: READ: Syntax error at `!': expecting RECTANGULAR or
+SYMMETRIC.
+
+matrix.sps:13.15: error: READ: Syntax error at `!': expecting identifier.
+
+matrix.sps:14: error: READ: Subcommand FORMAT may only be specified once.
+
+matrix.sps:15.15-15.22: error: READ: Syntax error at `'5XYZZY'': Unknown format
+XYZZY.
+
+matrix.sps:16: error: READ: Unknown format type `XYZZY'.
+
+matrix.sps:17.8: error: READ: Syntax error at `!': expecting FILE, FIELD, MODE,
+REREAD, or FORMAT.
+
+matrix.sps:18: error: READ: Required subcommand FIELD was not specified.
+
+matrix.sps:19: error: READ: SIZE is required for reading data into a full
+matrix (as opposed to a submatrix).
+
+matrix.sps:20: error: READ: Required subcommand FILE was not specified.
+
+matrix.sps:21: error: READ: 15 repetitions cannot fit in record width 10.
+
+matrix.sps:22: error: READ: FORMAT specifies field width 5 but BY specifies 2.
+
+matrix.sps:23: error: READ: FORMAT specifies 2 repetitions with record width
+10, which implies field width 5, but BY specifies field width 2.
+
+matrix.sps:24: error: MATRIX: SIZE must evaluate to a scalar or a 2-element
+vector, not a 2×2 matrix.
+
+matrix.sps:25: error: MATRIX: SIZE must evaluate to a scalar or a 2-element
+vector, not a 1×3 matrix.
+
+matrix.sps:26: error: MATRIX: Matrix dimensions -1×1 specified on SIZE are
+outside valid range.
+
+matrix.sps:28: error: MATRIX: Matrix dimensions 2×2 specified on SIZE differ
+from submatrix dimensions 1×3.
+
+matrix.sps:29: error: MATRIX: Cannot read non-square 1×3 matrix using READ with
+MODE=SYMMETRIC.
+])
+AT_CLEANUP
+