1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#!/bin/java bsh.Interpreter
source("TestHarness.bsh");
// basic
byte b = (byte)2;
byte b = 0xff;
byte b = 2;
i=b;
assert( i == 2 );
char c = 'A';
char c = 5;
short s = (short)2;
short s = 2;
int i = 2;
float f = 3.0f;
// In Java float's don't get auto cast in declarations
//assert( isEvalError("float f = 3.0"));
float f = 3.0;
double d = 3.0;
// promote
double d1 = 3.0f;
assert( d1.getType() == Double.TYPE );
long l1 = 5;
assert( l1.getType() == Long.TYPE );
l1 = (byte)5;
assert( l1.getType() == Long.TYPE );
// basic assignment promotion
int i2 = (byte)5;
long l1 = 5;
assert(l1==5);
long l2 = b;
assert(l2==2);
long l3=(byte)2;
/*
Unification of wrapper types with primitives
*/
Integer iw = 2;
Double dw = 2.0;
assert( iw == i );
assert( dw == b );
// preserve identity semantics
// .equal wrappers don't test ==
assert( !(iw == dw) );
assert( iw instanceof Integer );
assert( iw != null );
Integer in = null;
assert( in == null );
// Basic promotion of primitives
byte b1 = (byte)5;
short s1 = (short)5;
int i1 = 5;
long l1 = 5;
float f1 = 5.0f;
double d1 = 5.0;
char c1 = (char)42;
s1=b1;
i1=b1;
i1=s1;
i1=c1;
l1=b1;
l1=s1;
l1=c1;
l1=i1;
//l1=d1; // double to long?
f1=b1;
f1=s1;
f1=c1;
f1=i1;
d1=b1;
d1=s1;
d1=i1;
d1=l1;
// Numeric style promotion of primitive wrappers
// characters wrappers ok
Byte bw1 = (byte)5;
Short sw1 = (short)5;
Integer iw1 = 5;
Long lw1 = 5;
Float fw1 = 5.0f;
Double dw1 = 5.0;
Character cw1 = (char)42;
sw1=b1;
iw1=b1;
iw1=s1;
iw1=c1;
lw1=b1;
lw1=s1;
lw1=c1;
lw1=i1;
// lw1=d1; // double to Long?
fw1=b1;
fw1=s1;
fw1=c1;
fw1=i1;
dw1=b1;
dw1=s1;
dw1=i1;
dw1=l1;
double d123=3.0;
float f123=3.0;
d123=f123;
assert( d123.getType() == Double.TYPE );
assert( f123.getType() == Float.TYPE );
assert(isEvalError("f123=d123"));
assert(isEvalError("d123=true"));
assert(isEvalError("d123=null"));
complete();
|