Calq Test Cases

Calq is a web application that interprets a simple sequence of programming commands. What is Calq? Click here for more. I encourage you to try it out by putting your commands in the top text-box (the bottom one is for results).

This file presents a series of test cases for Calq, along with the expected results. If you enter the blue text into the top window, Calq should output the green text in the bottom window, after you press "Evaluate". If it does not, this indicates an error that needs to be addressed.

This is an on-going, iterative project. Often adding a new feature will "break" something, i.e., that something that used to work no longer does. While it is impractical to test for every possibility, this page presents a series of tests that the latest version of Calq should handle correctly.

  1. Functions embedded in functions.

    conv(1:3, 4:8)

    4 13 28 34 40 37 24

  2. Functions embedded in functions.

    x = 3:4;
    z = 1:5;
    y = conv(cos(conv(x, 2*z)), x)

    2.880510859951098 5.06492733204164 -0.9133825771002477 -5.3147141175460195 -0.5400558709060403 0.6932144643375593 -2.6677522466090475

  3. Using a function call

    x = 4:5;
    y = 8 - conv(x, 1:3)

    -4 -5 -14 -7

  4. Testing out parameters.

    params( (3) )
    params( [3] )

    3
    3


  5. Assembling a list.

    d0 = (1-sqrt(3))/(4*sqrt(2));
    d1 = -(3-sqrt(3))/(4*sqrt(2));
    d2 = (3+sqrt(3))/(4*sqrt(2));
    d3 = -(1+sqrt(3))/(4*sqrt(2));
    wavelet = [d0, d1, d2, d3];
    disp(wavelet)

    -0.12940952255126034 -0.2241438680420134 0.8365163037378077 -0.4829629131445341


  6. Function of a list.

    sum([ 9, 5, 3, 1 ])

    18


  7. Variable assignment, recall, overwrite.

    myvar = 0.125 + 6.7
    (3-4)*12/((-5+1+2*3)-(103-160+myvar))
    myvar = (3-4)*12/((-5+1+2*3)-(103-160+6/8));
    myvar

    6.825
    -0.22999520843315766

    myvar
      (double) -0.20600858369098712


  8. If statement, disp

    z = 4 + 3 + 1
    if (z==8)
        disp(z);
    end

    8
    8


  9. Testing For loops

    num = 0;
    for i=4:6
      for j = 7:10
        for k = 2:3
          num = num + k;
        end
      end
    end
    num

    num
      (double) 60


  10. Testing While loops


    num2 = 0;
    i = 6;
    while i > 3
      j = 7;
      while j < 11
        k = 2;
        while k <= 3
          num2 = num2 + k;
          k = k + 1;
        end
        j = j + 1;
      end
      i = i - 1;
    end
    num2

    num2
      (double) 60


  11. Nested if statements.

    for x = 1:4
      if (x==2)
          disp('the if is true');
      else
          if (x==3)
              disp('the elseif is true');
          else
              disp('went to the 2nd else block')
          end
      end
    end

    went to the 2nd else block
    the if is true
    the elseif is true
    went to the 2nd else block


  12. Here is an "elseif" example.

    for x = 0:4
        if (x==2)
            disp('two');
        elseif (x==3)
            disp('three');
        elseif (x==1)
            disp('one');
        else
            disp('x is not 1 2 or 3.');
        end
    end

    x is not 1 2 or 3.
    one
    two
    three
    x is not 1 2 or 3.


  13. Finding the average of an array of numbers.

    mylist = [ 9, 5, 3, 1 ];
    sum(mylist) / length(mylist)

    4.5


  14. Creating a list.

    a = 4
    disp(a:10-1)

    4
    4 5 6 7 8 9


  15. Choosing numbers from a list in one command.

    mylist = [ 9, 5, 3, 1, 2, 8, 4, 2, 6];
    a = 2;
    mylist(a:length(mylist)-1)

    5 3 1 2 8 4 2


  16. Here is an example of the "ls" command.

    disp('hello');
    ls
    disp('there');

    (Results vary, but should look like this:)
    hello
    there
    total 52K
    -rw-r--r-- 1 mweeks 75 Jan 5 22:16 cosplot
    -rw-r--r-- 1 mweeks 254 Jan 7 13:12 elseif.ex
    -rw-r--r-- 1 mweeks 460 Jan 1 12:24 ex1


  17. Sorting a list of numbers.

    mylist = [ 9, 5, 3, 1, 2, 8, 4, 2, 6];
    swap = 1;
    while (swap==1)
        swap = 0;
        % go through the list, swapping if out of order
        for index=1:length(mylist)-1
            if (mylist(index) > mylist(index+1))
                % swap the order of these two
                y = mylist(index);
                swap = 1;
                mylist(index) = mylist(index+1);
                mylist(index+1) = y;
            end
        end
    end
    % show the sorted array
    disp(mylist)

    1 2 2 3 4 5 6 8 9


  18. Plotting a sinusoid.

    t = 0:99;
    x = cos(2*pi*5*t/100);
    plot(x)

    This should look like:
    (image of the plot)



  19. Displaying strings

    a = 4;
    disp('hello ' + a);
    disp(a + ' hello');

    This should produce the following output:
    hello 4
    4 hello

  20. Working with complex numbers

    a3 = 3*j
    b = 1-a3

    This should produce the following output:
    0 + 3i
    1 - 3i

See file alltests.m, e.g. load('alltests.m');

v2.1.6 of alltests.m (used on the two below)
v2.1.5 results on alltests.m
v2.1.6 results on alltests.m


Disclaimer

This is an experimental project. Do not assume that the results are valid.

This project is licensed through the GNU General Public License. If you want a copy of the source code, contact me (the author) below. I may be interested in working collaboratively on this project. Be sure to put "calq" in the subject line of your e-mail.

-Michael Weeks, mweeks [at] cs.gsu.edu, copyright © 2007-2013.
Last update of this page: April 29, 2013.