vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java
author Martin Soch <Martin.Soch@oracle.com>
Tue, 05 Feb 2013 15:03:22 +0100
brancharithmetic
changeset 669 3754580b6c67
parent 657 b42bfe334128
child 676 eecf6077ec4e
permissions -rw-r--r--
Fixed error in neg64 found bu Lubo.
jaroslav@114
     1
/**
jaroslav@114
     2
 * Back 2 Browser Bytecode Translator
jaroslav@114
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@114
     4
 *
jaroslav@114
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@114
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@114
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@114
     8
 *
jaroslav@114
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@114
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@114
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@114
    12
 * GNU General Public License for more details.
jaroslav@114
    13
 *
jaroslav@114
    14
 * You should have received a copy of the GNU General Public License
jaroslav@114
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@114
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@114
    17
 */
jaroslav@114
    18
package org.apidesign.vm4brwsr;
jaroslav@114
    19
jaroslav@114
    20
import javax.script.Invocable;
jaroslav@114
    21
import javax.script.ScriptException;
jtulach@132
    22
import static org.testng.Assert.*;
jaroslav@114
    23
import org.testng.annotations.BeforeClass;
jaroslav@114
    24
import org.testng.annotations.Test;
jaroslav@114
    25
jaroslav@114
    26
/**
jaroslav@114
    27
 *
jaroslav@114
    28
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@114
    29
 */
jaroslav@114
    30
public class NumberTest {
jaroslav@114
    31
    @Test public void integerFromString() throws Exception {
jaroslav@248
    32
        assertExec("Can convert string to integer", Integer.class, "parseInt__ILjava_lang_String_2",
jaroslav@114
    33
            Double.valueOf(333), "333"
jaroslav@114
    34
        );
jaroslav@114
    35
    }
jaroslav@114
    36
jaroslav@114
    37
    @Test public void doubleFromString() throws Exception {
jaroslav@248
    38
        assertExec("Can convert string to double", Double.class, "parseDouble__DLjava_lang_String_2",
jaroslav@114
    39
            Double.valueOf(33.3), "33.3"
jaroslav@114
    40
        );
jaroslav@114
    41
    }
jaroslav@114
    42
jaroslav@114
    43
    @Test public void autoboxDouble() throws Exception {
jaroslav@248
    44
        assertExec("Autoboxing of doubles is OK", Numbers.class, "autoboxDblToString__Ljava_lang_String_2",
jaroslav@114
    45
            "3.3"
jaroslav@114
    46
        );
jaroslav@114
    47
    }
jtulach@132
    48
    
jtulach@132
    49
    @Test public void javalog1000() throws Exception {
jtulach@132
    50
        assertEquals(3.0, Math.log10(1000.0), 0.00003, "log_10(1000) == 3");
jtulach@132
    51
    }
jtulach@132
    52
jtulach@132
    53
    @Test public void jslog1000() throws Exception {
jaroslav@248
    54
        assertExec("log_10(1000) == 3", Math.class, "log10__DD", 
jtulach@132
    55
            Double.valueOf(3.0), 1000.0
jtulach@132
    56
        );
jtulach@132
    57
    }
jaroslav@178
    58
    
jaroslav@178
    59
    @Test public void javaRem() {
jaroslav@178
    60
        assertEquals(3, Numbers.rem(303, 10));
jaroslav@178
    61
    }
jaroslav@178
    62
    @Test public void jsRem() throws Exception {
jaroslav@248
    63
        assertExec("Should be three", Numbers.class, "rem__III", 
jaroslav@178
    64
            Double.valueOf(3.0), 303, 10
jaroslav@178
    65
        );
jaroslav@178
    66
    }
jaroslav@181
    67
    
jaroslav@181
    68
    @Test public void deserializeInt() throws Exception {
jaroslav@181
    69
        int exp = Numbers.deserInt();
jaroslav@248
    70
        assertExec("Should be the same", Numbers.class, "deserInt__I", 
jaroslav@181
    71
            Double.valueOf(exp)
jaroslav@181
    72
        );
jaroslav@181
    73
    }
jaroslav@185
    74
jaroslav@185
    75
    @Test public void deserializeSimpleLong() throws Exception {
jaroslav@248
    76
        assertExec("Should be 3454", Numbers.class, "deserLong__J_3B", 
jaroslav@185
    77
            Double.valueOf(3454), 
jaroslav@185
    78
            new byte[] { (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)13, (byte)126 }
jaroslav@185
    79
        );
jaroslav@185
    80
    }
jaroslav@185
    81
    /* XXX: JavaScript cannot represent as big longs as Java. 
jaroslav@185
    82
    @Test public void deserializeLargeLong() throws Exception {
jaroslav@185
    83
        final byte[] arr = new byte[] {
jaroslav@185
    84
            (byte)64, (byte)8, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0
jaroslav@185
    85
        };
jaroslav@185
    86
        long exp = Numbers.deserLong(arr);
jaroslav@248
    87
        assertExec("Should be " + exp, "org_apidesign_vm4brwsr_Numbers_deserLong__JAB", 
jaroslav@185
    88
            Double.valueOf(exp), arr);
jaroslav@185
    89
    }
jaroslav@185
    90
    */
jaroslav@181
    91
    
jaroslav@181
    92
    @Test public void deserializeFloatInJava() throws Exception {
jaroslav@181
    93
        float f = 54324.32423f;
jaroslav@181
    94
        float r = Numbers.deserFloat();
jaroslav@181
    95
        assertEquals(r, f, "Floats are the same");
jaroslav@181
    96
    }
jaroslav@181
    97
    
jaroslav@181
    98
    @Test public void deserializeFloatInJS() throws Exception {
jaroslav@181
    99
        float f = 54324.32423f;
jaroslav@248
   100
        assertExec("Should be the same", Numbers.class, "deserFloat__F", 
jaroslav@181
   101
            Double.valueOf(f)
jaroslav@181
   102
        );
jaroslav@181
   103
    }
jaroslav@114
   104
jaroslav@185
   105
    @Test public void deserializeDoubleInJava() throws Exception {
jaroslav@185
   106
        double f = 3.0;
jaroslav@185
   107
        double r = Numbers.deserDouble();
jaroslav@185
   108
        assertEquals(r, f, 0.001, "Doubles are the same");
jaroslav@185
   109
    }
jaroslav@114
   110
    
jaroslav@185
   111
    @Test public void deserializeDoubleInJS() throws Exception {
jaroslav@185
   112
        double f = 3.0;
jaroslav@248
   113
        assertExec("Should be the same", Numbers.class, "deserDouble__D", f);
jaroslav@185
   114
    }
jaroslav@185
   115
    /*
jaroslav@185
   116
    @Test public void serDouble() throws IOException {
jaroslav@185
   117
        double f = 3.0;
jaroslav@185
   118
        ByteArrayOutputStream os = new ByteArrayOutputStream();
jaroslav@185
   119
        DataOutputStream d = new DataOutputStream(os);
jaroslav@185
   120
        d.writeLong(3454);
jaroslav@185
   121
        d.close();
jaroslav@185
   122
        
jaroslav@185
   123
        StringBuilder sb = new StringBuilder();
jaroslav@185
   124
        byte[] arr = os.toByteArray();
jaroslav@185
   125
        for (int i = 0; i < arr.length; i++) {
jaroslav@185
   126
            sb.append("(byte)").append(arr[i]).append(", ");
jaroslav@185
   127
        }
jaroslav@185
   128
        fail("" + sb);
jaroslav@185
   129
    }
jaroslav@185
   130
*/    
jaroslav@186
   131
    @Test public void fiveInStringJS() throws Exception {
jaroslav@186
   132
        String s = Numbers.intToString();
jaroslav@186
   133
        assertExec("Should be the same: " + s, 
jaroslav@248
   134
            Numbers.class, "intToString__Ljava_lang_String_2", 
jaroslav@186
   135
            s
jaroslav@186
   136
        );
jaroslav@186
   137
    }
jaroslav@187
   138
jaroslav@187
   139
    @Test public void sevenInStringJS() throws Exception {
jaroslav@187
   140
        String s = Numbers.floatToString();
jaroslav@187
   141
        assertExec("Should be the same: " + s, 
jaroslav@248
   142
            Numbers.class, "floatToString__Ljava_lang_String_2", 
jaroslav@187
   143
            s
jaroslav@187
   144
        );
jaroslav@187
   145
    }
jaroslav@186
   146
    
Martin@615
   147
    @Test public void longConversion() throws Exception {
Martin@615
   148
        assertExec("Long from cPool",
Martin@615
   149
            Numbers.class, "conversionL__J", 
Martin@615
   150
            Double.valueOf(Long.MAX_VALUE)
Martin@615
   151
        );
Martin@615
   152
    }
Martin@615
   153
    
Martin@630
   154
    @Test public void longNegate1() throws Exception {
Martin@630
   155
        final long res = -0x00fa37d7763e0ca1l;
Martin@630
   156
        assertExec("Long negate",
Martin@630
   157
            Numbers.class, "negL__J_3B", 
Martin@630
   158
            Double.valueOf(res),
Martin@630
   159
                new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }
Martin@630
   160
        );
Martin@630
   161
    }
Martin@630
   162
    
Martin@630
   163
    @Test public void longNegate2() throws Exception {
Martin@630
   164
        final long res = -0x80fa37d7763e0ca1l;
Martin@630
   165
        assertExec("Long negate",
Martin@630
   166
            Numbers.class, "negL__J_3B", 
Martin@630
   167
            Double.valueOf(res),
Martin@630
   168
                new byte[] { (byte)0x80, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }
Martin@630
   169
        );
Martin@630
   170
    }
Martin@630
   171
    
Martin@669
   172
    @Test public void longNegate3() throws Exception {
Martin@669
   173
        final long res = -0xfffffffffffffeddl;
Martin@669
   174
        assertExec("Long negate",
Martin@669
   175
            Numbers.class, "negL__J_3B",
Martin@669
   176
            Double.valueOf(res),
Martin@669
   177
                new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd }
Martin@669
   178
        );
Martin@669
   179
    }
Martin@669
   180
Martin@669
   181
    
Martin@616
   182
    @Test public void longAddOverflow() throws Exception {
Martin@616
   183
        final long res = Long.MAX_VALUE + 1l;
Martin@616
   184
        assertExec("Addition 1+MAX",
Martin@616
   185
            Numbers.class, "addL__J_3B_3B", 
Martin@616
   186
            Double.valueOf(res),
Martin@616
   187
                new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff },
Martin@616
   188
                new byte[] { (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)1 }
Martin@616
   189
        );
Martin@616
   190
    }
Martin@616
   191
    
Martin@616
   192
    @Test public void longAddMaxAndMax() throws Exception {
Martin@616
   193
        final long res = Long.MAX_VALUE + Long.MAX_VALUE;
Martin@616
   194
        assertExec("Addition MAX+MAX",
Martin@616
   195
            Numbers.class, "addL__J_3B_3B", 
Martin@616
   196
            Double.valueOf(res),
Martin@616
   197
            new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff },
Martin@616
   198
            new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }
Martin@616
   199
        );
Martin@616
   200
    }
Martin@616
   201
    
Martin@620
   202
    @Test public void longSubUnderflow() throws Exception {
Martin@620
   203
        final long res = Long.MIN_VALUE - 1l;
Martin@620
   204
        assertExec("Subtraction MIN-1",
Martin@620
   205
            Numbers.class, "subL__J_3B_3B", 
Martin@620
   206
            Double.valueOf(res),
Martin@620
   207
                new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
Martin@620
   208
                new byte[] { (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)1 }
Martin@620
   209
        );
Martin@620
   210
    }
Martin@620
   211
    
Martin@620
   212
    @Test public void longSubMinAndMin() throws Exception {
Martin@620
   213
        final long res = Long.MIN_VALUE - Long.MIN_VALUE;
Martin@620
   214
        assertExec("Subtraction MIN-MIN",
Martin@620
   215
            Numbers.class, "subL__J_3B_3B", 
Martin@620
   216
            Double.valueOf(res),
Martin@620
   217
            new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
Martin@620
   218
            new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }
Martin@620
   219
        );
Martin@620
   220
    }
Martin@620
   221
    
Martin@620
   222
    @Test public void longSubMinAndMax() throws Exception {
Martin@620
   223
        final long res = Long.MIN_VALUE - Long.MAX_VALUE;
Martin@620
   224
        assertExec("Subtraction MIN-MAX",
Martin@620
   225
            Numbers.class, "subL__J_3B_3B", 
Martin@620
   226
            Double.valueOf(res),
Martin@620
   227
            new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
Martin@620
   228
            new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }
Martin@620
   229
        );
Martin@620
   230
    }
Martin@620
   231
    
Martin@657
   232
    @Test public void longMultiplyMax() throws Exception {
Martin@657
   233
        final long res = Long.MAX_VALUE * 2l;
Martin@657
   234
        assertExec("Multiplication MAX*2",
Martin@657
   235
            Numbers.class, "mulL__J_3B_3B",
Martin@657
   236
            Double.valueOf(res),
Martin@657
   237
            new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff },
Martin@657
   238
            new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02 }
Martin@657
   239
        );
Martin@657
   240
    }
Martin@657
   241
    
Martin@657
   242
    @Test public void longMultiplyMaxAndMax() throws Exception {
Martin@657
   243
        final long res = Long.MAX_VALUE * Long.MAX_VALUE;
Martin@657
   244
        assertExec("Multiplication MAX*MAX",
Martin@657
   245
            Numbers.class, "mulL__J_3B_3B",
Martin@657
   246
            Double.valueOf(res),
Martin@657
   247
            new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff },
Martin@657
   248
            new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }
Martin@657
   249
        );
Martin@657
   250
    }
Martin@657
   251
    
Martin@657
   252
    @Test public void longMultiplyMin() throws Exception {
Martin@657
   253
        final long res = Long.MIN_VALUE * 2l;
Martin@657
   254
        assertExec("Multiplication MIN*2",
Martin@657
   255
            Numbers.class, "mulL__J_3B_3B",
Martin@657
   256
            Double.valueOf(res),
Martin@657
   257
            new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
Martin@657
   258
            new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02 }
Martin@657
   259
        );
Martin@657
   260
    }
Martin@657
   261
    
Martin@657
   262
    @Test public void longMultiplyMinAndMin() throws Exception {
Martin@657
   263
        final long res = Long.MIN_VALUE * Long.MIN_VALUE;
Martin@657
   264
        assertExec("Multiplication MIN*2",
Martin@657
   265
            Numbers.class, "mulL__J_3B_3B",
Martin@657
   266
            Double.valueOf(res),
Martin@657
   267
            new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
Martin@657
   268
            new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }
Martin@657
   269
        );
Martin@657
   270
    }
Martin@657
   271
    
Martin@657
   272
    @Test public void longMultiplyPrecision() throws Exception {
Martin@657
   273
        final long res = 0x00fa37d7763e0ca1l * 0xa7b3432fff00123el;
Martin@657
   274
        assertExec("Multiplication",
Martin@657
   275
            Numbers.class, "mulL__J_3B_3B",
Martin@657
   276
            Double.valueOf(res),
Martin@657
   277
            new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
Martin@657
   278
            new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
Martin@657
   279
        );
Martin@657
   280
    }
Martin@657
   281
    
Martin@617
   282
    @Test public void longShiftL1() throws Exception {
Martin@617
   283
        final long res = 0x00fa37d7763e0ca1l << 5;
Martin@618
   284
        assertExec("Long << 5",
Martin@617
   285
            Numbers.class, "shlL__J_3BI", 
Martin@617
   286
            Double.valueOf(res),
Martin@617
   287
                new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
Martin@618
   288
                5);
Martin@617
   289
    }
Martin@617
   290
    
Martin@617
   291
    @Test public void longShiftL2() throws Exception {
Martin@617
   292
        final long res = 0x00fa37d7763e0ca1l << 32;
Martin@618
   293
        assertExec("Long << 32",
Martin@617
   294
            Numbers.class, "shlL__J_3BI", 
Martin@617
   295
            Double.valueOf(res),
Martin@617
   296
                new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
Martin@618
   297
                32);
Martin@617
   298
    }
Martin@617
   299
    
Martin@617
   300
    @Test public void longShiftL3() throws Exception {
Martin@617
   301
        final long res = 0x00fa37d7763e0ca1l << 45;
Martin@618
   302
        assertExec("Long << 45",
Martin@617
   303
            Numbers.class, "shlL__J_3BI", 
Martin@617
   304
            Double.valueOf(res),
Martin@617
   305
                new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
Martin@618
   306
                45);
Martin@618
   307
    }
Martin@618
   308
    
Martin@618
   309
    @Test public void longShiftR1() throws Exception {
Martin@618
   310
        final long res = 0x00fa37d7763e0ca1l >> 5;
Martin@618
   311
        assertExec("Long >> 5",
Martin@618
   312
            Numbers.class, "shrL__J_3BI", 
Martin@618
   313
            Double.valueOf(res),
Martin@618
   314
                new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
Martin@618
   315
                5);
Martin@618
   316
    }
Martin@618
   317
    
Martin@618
   318
    @Test public void longShiftR2() throws Exception {
Martin@618
   319
        final long res = 0x00fa37d7763e0ca1l >> 32;
Martin@618
   320
        assertExec("Long >> 32",
Martin@618
   321
            Numbers.class, "shrL__J_3BI", 
Martin@618
   322
            Double.valueOf(res),
Martin@618
   323
                new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
Martin@618
   324
                32);
Martin@618
   325
    }
Martin@618
   326
    
Martin@618
   327
    @Test public void longShiftR3() throws Exception {
Martin@618
   328
        final long res = 0x00fa37d7763e0ca1l >> 45;
Martin@618
   329
        assertExec("Long >> 45",
Martin@618
   330
            Numbers.class, "shrL__J_3BI", 
Martin@618
   331
            Double.valueOf(res),
Martin@618
   332
                new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
Martin@618
   333
                45);
Martin@617
   334
    }
Martin@617
   335
    
Martin@629
   336
    @Test public void longUShiftR1() throws Exception {
Martin@629
   337
        final long res = 0x00fa37d7763e0ca1l >>> 5;
Martin@629
   338
        assertExec("Long >>> 5",
Martin@629
   339
            Numbers.class, "ushrL__J_3BI", 
Martin@629
   340
            Double.valueOf(res),
Martin@629
   341
                new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
Martin@629
   342
                5);
Martin@629
   343
    }
Martin@629
   344
    
Martin@629
   345
    @Test public void longUShiftR2() throws Exception {
Martin@629
   346
        final long res = 0x00fa37d7763e0ca1l >>> 45;
Martin@629
   347
        assertExec("Long >>> 45",
Martin@629
   348
            Numbers.class, "ushrL__J_3BI", 
Martin@629
   349
            Double.valueOf(res),
Martin@629
   350
                new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
Martin@629
   351
                45);
Martin@629
   352
    }
Martin@629
   353
    
Martin@629
   354
    @Test public void longUShiftR3() throws Exception {
Martin@629
   355
        final long res = 0xf0fa37d7763e0ca1l >>> 5;
Martin@629
   356
        assertExec("Long >>> 5",
Martin@629
   357
            Numbers.class, "ushrL__J_3BI", 
Martin@629
   358
            Double.valueOf(res),
Martin@629
   359
                new byte[] { (byte)0xf0, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
Martin@629
   360
                5);
Martin@629
   361
    }
Martin@629
   362
    
Martin@629
   363
    @Test public void longUShiftR4() throws Exception {
Martin@629
   364
        final long res = 0xf0fa37d7763e0ca1l >>> 45;
Martin@629
   365
        assertExec("Long >>> 45",
Martin@629
   366
            Numbers.class, "ushrL__J_3BI", 
Martin@629
   367
            Double.valueOf(res),
Martin@629
   368
                new byte[] { (byte)0xf0, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
Martin@629
   369
                45);
Martin@629
   370
    }
Martin@629
   371
    
Martin@627
   372
    @Test public void longAnd() throws Exception {
Martin@627
   373
        final long res = 0x00fa37d7763e0ca1l & 0xa7b3432fff00123el;
Martin@627
   374
        assertExec("LOng binary AND",
Martin@627
   375
            Numbers.class, "andL__J_3B_3B", 
Martin@627
   376
            Double.valueOf(res),
Martin@627
   377
            new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
Martin@627
   378
            new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
Martin@627
   379
        );
Martin@627
   380
    }
Martin@627
   381
    
Martin@627
   382
    @Test public void longOr() throws Exception {
Martin@627
   383
        final long res = 0x00fa37d7763e0ca1l | 0xa7b3432fff00123el;
Martin@627
   384
        assertExec("Long binary OR",
Martin@627
   385
            Numbers.class, "orL__J_3B_3B", 
Martin@627
   386
            Double.valueOf(res),
Martin@627
   387
            new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
Martin@627
   388
            new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
Martin@627
   389
        );
Martin@627
   390
    }
Martin@627
   391
    
Martin@628
   392
    @Test public void longXor1() throws Exception {
Martin@628
   393
        final long res = 0x00fa37d7763e0ca1l ^ 0xa7b3432fff00123el;
Martin@628
   394
        assertExec("Long binary XOR",
Martin@628
   395
            Numbers.class, "xorL__J_3B_3B", 
Martin@628
   396
            Double.valueOf(res),
Martin@628
   397
            new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
Martin@628
   398
            new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
Martin@628
   399
        );
Martin@628
   400
    }
Martin@628
   401
    
Martin@628
   402
    @Test public void longXor2() throws Exception {
Martin@628
   403
        final long res = 0x00fa37d7763e0ca1l ^ 0x00000000ff00123el;
Martin@628
   404
        assertExec("Long binary XOR",
Martin@628
   405
            Numbers.class, "xorL__J_3B_3B", 
Martin@628
   406
            Double.valueOf(res),
Martin@628
   407
            new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
Martin@628
   408
            new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
Martin@628
   409
        );
Martin@628
   410
    }
Martin@628
   411
    
Martin@628
   412
    @Test public void longXor3() throws Exception {
Martin@628
   413
        final long res = 0x00000000763e0ca1l ^ 0x00000000ff00123el;
Martin@628
   414
        assertExec("Long binary XOR",
Martin@628
   415
            Numbers.class, "xorL__J_3B_3B", 
Martin@628
   416
            Double.valueOf(res),
Martin@628
   417
            new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
Martin@628
   418
            new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
Martin@628
   419
        );
Martin@628
   420
    }
Martin@628
   421
    
jaroslav@114
   422
    private static CharSequence codeSeq;
jaroslav@114
   423
    private static Invocable code;
jaroslav@114
   424
jaroslav@114
   425
    @BeforeClass
jaroslav@114
   426
    public void compileTheCode() throws Exception {
jaroslav@114
   427
        if (codeSeq == null) {
jaroslav@114
   428
            StringBuilder sb = new StringBuilder();
jaroslav@114
   429
            code = StaticMethodTest.compileClass(sb, "org/apidesign/vm4brwsr/Numbers");
jaroslav@114
   430
            codeSeq = sb;
jaroslav@114
   431
        }
jaroslav@114
   432
    }
jaroslav@114
   433
jaroslav@114
   434
    private static void assertExec(
Martin@582
   435
        String msg, Class<?> clazz, String method, Object expRes, Object... args) throws Exception
Martin@582
   436
    {
Martin@582
   437
        Object ret = TestUtils.execCode(code, codeSeq, msg, clazz, method, expRes, args);
Martin@582
   438
        if (ret == null) {
jaroslav@114
   439
            return;
jaroslav@114
   440
        }
jtulach@132
   441
        if (expRes instanceof Double && ret instanceof Double) {
jtulach@132
   442
            double expD = ((Double)expRes).doubleValue();
jtulach@132
   443
            double retD = ((Double)ret).doubleValue();
Martin@616
   444
            assertEquals(retD, expD, 0.000004, msg + " "
Martin@616
   445
                    + StaticMethodTest.dumpJS(codeSeq));
jtulach@132
   446
            return;
jtulach@132
   447
        }
Martin@616
   448
        assertEquals(ret, expRes, msg + " " + StaticMethodTest.dumpJS(codeSeq));
jaroslav@114
   449
    }
jaroslav@114
   450
    
jaroslav@114
   451
}