Home » Archimedes archive » Acorn User » AU 1997-10 A.adf » Extras » Apple][e/PD/BOB/ARMBOB/!ArmBob/progs/main/testformat

Apple][e/PD/BOB/ARMBOB/!ArmBob/progs/main/testformat

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1997-10 A.adf » Extras
Filename: Apple][e/PD/BOB/ARMBOB/!ArmBob/progs/main/testformat
Read OK:
File size: 03D4 bytes
Load address: 0000
Exec address: 0000
File contents
/* tests of format(n,w,p) */

main()
{
  print(" tests of format(n,w,p)");
  w0 = 12; p0 = 3;
  print(" for w = ",w0,", p = ",p0);
  print("\n\n last characters should align with\n");
  print(format( "|", w0, p0 ),"  for w = ",w0,"\n");
  print(format( "|", w0, p0 ),"\n");

  format_test( -0.00178, w0, p0 );
  format_test(  0.0, w0, p0 );
  format_test(  1234.56789, w0, p0 );
  format_test( -1234.56789, w0, p0 );
  format_test(  123456789, w0, p0 );
  format_test( -123456789, w0, p0 );
  format_test( -54321, w0, p0 );
  format_test(  0.999999, w0, p0 );
  format_test( -0.999999, w0, p0 );
  format_test( -0.00001, w0, p0 );
  format_test( 0, w0, p0);
  format_test( "test string", w0, p0 );
}

format_test(n,w,p)
{
  switch (typeof(n))
    {
      case REAL   :type$ = "real n:    ";break;
      case INTEGER:type$ = "integer n: ";break;
      case STRING :type$ = "string n:  ";
    }   
  print(format(n,w0,p0),"  for ",type$,n,"\n");
  print(format("|",w0,p0),"\n");
}

00000000  2f 2a 20 74 65 73 74 73  20 6f 66 20 66 6f 72 6d  |/* tests of form|
00000010  61 74 28 6e 2c 77 2c 70  29 20 2a 2f 0a 0a 6d 61  |at(n,w,p) */..ma|
00000020  69 6e 28 29 0a 7b 0a 20  20 70 72 69 6e 74 28 22  |in().{.  print("|
00000030  20 74 65 73 74 73 20 6f  66 20 66 6f 72 6d 61 74  | tests of format|
00000040  28 6e 2c 77 2c 70 29 22  29 3b 0a 20 20 77 30 20  |(n,w,p)");.  w0 |
00000050  3d 20 31 32 3b 20 70 30  20 3d 20 33 3b 0a 20 20  |= 12; p0 = 3;.  |
00000060  70 72 69 6e 74 28 22 20  66 6f 72 20 77 20 3d 20  |print(" for w = |
00000070  22 2c 77 30 2c 22 2c 20  70 20 3d 20 22 2c 70 30  |",w0,", p = ",p0|
00000080  29 3b 0a 20 20 70 72 69  6e 74 28 22 5c 6e 5c 6e  |);.  print("\n\n|
00000090  20 6c 61 73 74 20 63 68  61 72 61 63 74 65 72 73  | last characters|
000000a0  20 73 68 6f 75 6c 64 20  61 6c 69 67 6e 20 77 69  | should align wi|
000000b0  74 68 5c 6e 22 29 3b 0a  20 20 70 72 69 6e 74 28  |th\n");.  print(|
000000c0  66 6f 72 6d 61 74 28 20  22 7c 22 2c 20 77 30 2c  |format( "|", w0,|
000000d0  20 70 30 20 29 2c 22 20  20 66 6f 72 20 77 20 3d  | p0 ),"  for w =|
000000e0  20 22 2c 77 30 2c 22 5c  6e 22 29 3b 0a 20 20 70  | ",w0,"\n");.  p|
000000f0  72 69 6e 74 28 66 6f 72  6d 61 74 28 20 22 7c 22  |rint(format( "|"|
00000100  2c 20 77 30 2c 20 70 30  20 29 2c 22 5c 6e 22 29  |, w0, p0 ),"\n")|
00000110  3b 0a 0a 20 20 66 6f 72  6d 61 74 5f 74 65 73 74  |;..  format_test|
00000120  28 20 2d 30 2e 30 30 31  37 38 2c 20 77 30 2c 20  |( -0.00178, w0, |
00000130  70 30 20 29 3b 0a 20 20  66 6f 72 6d 61 74 5f 74  |p0 );.  format_t|
00000140  65 73 74 28 20 20 30 2e  30 2c 20 77 30 2c 20 70  |est(  0.0, w0, p|
00000150  30 20 29 3b 0a 20 20 66  6f 72 6d 61 74 5f 74 65  |0 );.  format_te|
00000160  73 74 28 20 20 31 32 33  34 2e 35 36 37 38 39 2c  |st(  1234.56789,|
00000170  20 77 30 2c 20 70 30 20  29 3b 0a 20 20 66 6f 72  | w0, p0 );.  for|
00000180  6d 61 74 5f 74 65 73 74  28 20 2d 31 32 33 34 2e  |mat_test( -1234.|
00000190  35 36 37 38 39 2c 20 77  30 2c 20 70 30 20 29 3b  |56789, w0, p0 );|
000001a0  0a 20 20 66 6f 72 6d 61  74 5f 74 65 73 74 28 20  |.  format_test( |
000001b0  20 31 32 33 34 35 36 37  38 39 2c 20 77 30 2c 20  | 123456789, w0, |
000001c0  70 30 20 29 3b 0a 20 20  66 6f 72 6d 61 74 5f 74  |p0 );.  format_t|
000001d0  65 73 74 28 20 2d 31 32  33 34 35 36 37 38 39 2c  |est( -123456789,|
000001e0  20 77 30 2c 20 70 30 20  29 3b 0a 20 20 66 6f 72  | w0, p0 );.  for|
000001f0  6d 61 74 5f 74 65 73 74  28 20 2d 35 34 33 32 31  |mat_test( -54321|
00000200  2c 20 77 30 2c 20 70 30  20 29 3b 0a 20 20 66 6f  |, w0, p0 );.  fo|
00000210  72 6d 61 74 5f 74 65 73  74 28 20 20 30 2e 39 39  |rmat_test(  0.99|
00000220  39 39 39 39 2c 20 77 30  2c 20 70 30 20 29 3b 0a  |9999, w0, p0 );.|
00000230  20 20 66 6f 72 6d 61 74  5f 74 65 73 74 28 20 2d  |  format_test( -|
00000240  30 2e 39 39 39 39 39 39  2c 20 77 30 2c 20 70 30  |0.999999, w0, p0|
00000250  20 29 3b 0a 20 20 66 6f  72 6d 61 74 5f 74 65 73  | );.  format_tes|
00000260  74 28 20 2d 30 2e 30 30  30 30 31 2c 20 77 30 2c  |t( -0.00001, w0,|
00000270  20 70 30 20 29 3b 0a 20  20 66 6f 72 6d 61 74 5f  | p0 );.  format_|
00000280  74 65 73 74 28 20 30 2c  20 77 30 2c 20 70 30 29  |test( 0, w0, p0)|
00000290  3b 0a 20 20 66 6f 72 6d  61 74 5f 74 65 73 74 28  |;.  format_test(|
000002a0  20 22 74 65 73 74 20 73  74 72 69 6e 67 22 2c 20  | "test string", |
000002b0  77 30 2c 20 70 30 20 29  3b 0a 7d 0a 0a 66 6f 72  |w0, p0 );.}..for|
000002c0  6d 61 74 5f 74 65 73 74  28 6e 2c 77 2c 70 29 0a  |mat_test(n,w,p).|
000002d0  7b 0a 20 20 73 77 69 74  63 68 20 28 74 79 70 65  |{.  switch (type|
000002e0  6f 66 28 6e 29 29 0a 20  20 20 20 7b 0a 20 20 20  |of(n)).    {.   |
000002f0  20 20 20 63 61 73 65 20  52 45 41 4c 20 20 20 3a  |   case REAL   :|
00000300  74 79 70 65 24 20 3d 20  22 72 65 61 6c 20 6e 3a  |type$ = "real n:|
00000310  20 20 20 20 22 3b 62 72  65 61 6b 3b 0a 20 20 20  |    ";break;.   |
00000320  20 20 20 63 61 73 65 20  49 4e 54 45 47 45 52 3a  |   case INTEGER:|
00000330  74 79 70 65 24 20 3d 20  22 69 6e 74 65 67 65 72  |type$ = "integer|
00000340  20 6e 3a 20 22 3b 62 72  65 61 6b 3b 0a 20 20 20  | n: ";break;.   |
00000350  20 20 20 63 61 73 65 20  53 54 52 49 4e 47 20 3a  |   case STRING :|
00000360  74 79 70 65 24 20 3d 20  22 73 74 72 69 6e 67 20  |type$ = "string |
00000370  6e 3a 20 20 22 3b 0a 20  20 20 20 7d 20 20 20 0a  |n:  ";.    }   .|
00000380  20 20 70 72 69 6e 74 28  66 6f 72 6d 61 74 28 6e  |  print(format(n|
00000390  2c 77 30 2c 70 30 29 2c  22 20 20 66 6f 72 20 22  |,w0,p0),"  for "|
000003a0  2c 74 79 70 65 24 2c 6e  2c 22 5c 6e 22 29 3b 0a  |,type$,n,"\n");.|
000003b0  20 20 70 72 69 6e 74 28  66 6f 72 6d 61 74 28 22  |  print(format("|
000003c0  7c 22 2c 77 30 2c 70 30  29 2c 22 5c 6e 22 29 3b  ||",w0,p0),"\n");|
000003d0  0a 7d 0a 0a                                       |.}..|
000003d4