Libraryless. Click here for Pure Java version (5993L/33K).
1 | svoid test_TypeSystem() { |
2 | GOperator<Class> iround = new GOperator<Class>("iround").arg(double.class).returns(int.class); |
3 | GOperator<Class> plus_int = new GOperator<Class>("plus_int").arg(int.class).arg(int.class).returns(int.class); |
4 | GOperator<Class> plus_dbl = new GOperator<Class>("plus_dbl").arg(double.class).arg(double.class).returns(double.class); |
5 | print(iround); |
6 | print(plus_int); |
7 | print(plus_dbl); |
8 | |
9 | GPolymorphicOperator<Class> plus = new("+", plus_int, plus_dbl); |
10 | print(plus.toStringWithDefinitions()); |
11 | |
12 | new TypeSystem<Class> ts; |
13 | assertTrueVerbose(ts.operatorCanTakeArguments(plus_dbl, double.class, double.class)); |
14 | assertFalseVerbose(ts.operatorCanTakeArguments(plus_dbl, double.class, int.class)); |
15 | assertFalseVerbose(ts.operatorCanTakeArguments(plus_dbl, int.class, double.class)); |
16 | assertFalseVerbose(ts.operatorCanTakeArguments(plus_dbl, double.class)); |
17 | assertFalseVerbose(ts.operatorCanTakeArguments(plus_dbl, double.class, double.class, double.class)); |
18 | |
19 | assertEqualsVerbose(ll(plus_int), ts.resolve(plus, int.class, int.class)); |
20 | assertEqualsVerbose(ll(plus_dbl), ts.resolve(plus, double.class, double.class)); |
21 | |
22 | // can't resolve because we haven't defined any subtype relations so int and double are incompatible |
23 | assertEqualsVerbose(ll(), ts.resolve(plus, int.class, double.class)); |
24 | |
25 | // Now let's test subtypes. Let's say an int is convertible to a double. |
26 | ts.isActualSupertypeOf = (a, b) -> a == double.class && b == int.class; |
27 | |
28 | assertTrueVerbose(ts.operatorCanTakeArguments(plus_int, int.class, int.class)); |
29 | assertFalseVerbose(ts.operatorCanTakeArguments(plus_int, double.class, int.class)); |
30 | assertTrueVerbose(ts.operatorCanTakeArguments(plus_dbl, int.class, int.class)); |
31 | assertTrueVerbose(ts.operatorCanTakeArguments(plus_dbl, double.class, int.class)); |
32 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1033965 |
Snippet name: | test_TypeSystem (OK) |
Eternal ID of this version: | #1033965/4 |
Text MD5: | 8565b8705732f8d799ceeb332cb372d5 |
Transpilation MD5: | 3fd6411c3ce5718697414eddfadb64b9 |
Author: | stefan |
Category: | javax / scripting |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-01-15 00:21:06 |
Source code size: | 1856 bytes / 32 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 133 / 217 |
Version history: | 3 change(s) |
Referenced in: | [show references] |