[LON-CAPA-cvs] cvs: loncom /homework/caparesponse test.pl

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 29 Sep 2006 20:56:39 -0000


albertel		Fri Sep 29 16:56:39 2006 EDT

  Modified files:              
    /loncom/homework/caparesponse	test.pl 
  Log:
  - reverting to 1.2
  
  
Index: loncom/homework/caparesponse/test.pl
diff -u loncom/homework/caparesponse/test.pl:1.3 loncom/homework/caparesponse/test.pl:1.4
--- loncom/homework/caparesponse/test.pl:1.3	Fri Sep 29 16:55:36 2006
+++ loncom/homework/caparesponse/test.pl	Fri Sep 29 16:56:38 2006
@@ -1,70 +1,14 @@
 use strict;
-use warnings;
+use capa;
 
-my $n = 0;
-my $total = 0;
-my $num_left = 0;
-my @order;
-
-sub factorial {
-    my $input = CORE::int(shift);
-    return "Error - unable to take factorial of an negative number ($input)" if $input < 0;
-    return "Error - factorial result is greater than system limit ($input)" if $input > 170;
-    return 1 if $input == 0;
-    my $result = 1; 
-    for (my $i=2; $i<=$input; $i++) { $result *= $i }
-    return $result;
-}
-
-sub init {
-    my ($size) = @_;
-    @order = (0..$size-1);
-    $n = $size;
-    $total = $num_left = &factorial($size);
-}
-
-sub get_next {
-    if ($num_left == $total) {
-	$num_left--;
-	return @order;
-    }
-
-
-    # Find largest index j with a[j] < a[j+1]
-
-    my $j = scalar(@order) - 2;
-    while ($order[$j] > $order[$j+1]) {
-	$j--;
-    }
-
-    # Find index k such that a[k] is smallest integer
-    # greater than a[j] to the right of a[j]
-
-    my $k = scalar(@order) - 1;
-    while ($order[$j] > $order[$k]) {
-	$k--;
-    }
-
-    # Interchange a[j] and a[k]
-
-    @order[($k,$j)] = @order[($j,$k)];
-
-    # Put tail end of permutation after jth position in increasing order
-
-    my $r = scalar(@order) - 1;
-    my $s = $j + 1;
-
-    while ($r > $s) {
-	@order[($s,$r)]=@order[($r,$s)];
-	$r--;
-	$s++;
-    }
-
-    $num_left--;
-    return(@order);
-}
-
-&init(9);
-while($num_left) {
-    print(join(':',&get_next()).$/);
-}
+my $unit="N";
+my $answer="3.4 N";
+my $scaled="3.2";
+print("\n return code is (should be 6)".&capa::caparesponse_get_real_response($unit,$answer,\$scaled));
+print("\nscaled (should be 0.0034) ".$scaled." unit $unit answer $answer");
+$unit="m";
+$answer="3.4 mm/J";
+$scaled=3.2;
+print("\n return code is (should be 15)".&capa::caparesponse_get_real_response($unit,$answer,\$scaled));
+print("\nscaled (should be 3.2) ".$scaled." unit $unit answer $answer");
+print("\n");