Libraryless. Click here for Pure Java version (5993L/33K).
svoid test_TypeSystem() { GOperator<Class> iround = new GOperator<Class>("iround").arg(double.class).returns(int.class); GOperator<Class> plus_int = new GOperator<Class>("plus_int").arg(int.class).arg(int.class).returns(int.class); GOperator<Class> plus_dbl = new GOperator<Class>("plus_dbl").arg(double.class).arg(double.class).returns(double.class); print(iround); print(plus_int); print(plus_dbl); GPolymorphicOperator<Class> plus = new("+", plus_int, plus_dbl); print(plus.toStringWithDefinitions()); new TypeSystem<Class> ts; assertTrueVerbose(ts.operatorCanTakeArguments(plus_dbl, double.class, double.class)); assertFalseVerbose(ts.operatorCanTakeArguments(plus_dbl, double.class, int.class)); assertFalseVerbose(ts.operatorCanTakeArguments(plus_dbl, int.class, double.class)); assertFalseVerbose(ts.operatorCanTakeArguments(plus_dbl, double.class)); assertFalseVerbose(ts.operatorCanTakeArguments(plus_dbl, double.class, double.class, double.class)); assertEqualsVerbose(ll(plus_int), ts.resolve(plus, int.class, int.class)); assertEqualsVerbose(ll(plus_dbl), ts.resolve(plus, double.class, double.class)); // can't resolve because we haven't defined any subtype relations so int and double are incompatible assertEqualsVerbose(ll(), ts.resolve(plus, int.class, double.class)); // Now let's test subtypes. Let's say an int is convertible to a double. ts.isActualSupertypeOf = (a, b) -> a == double.class && b == int.class; assertTrueVerbose(ts.operatorCanTakeArguments(plus_int, int.class, int.class)); assertFalseVerbose(ts.operatorCanTakeArguments(plus_int, double.class, int.class)); assertTrueVerbose(ts.operatorCanTakeArguments(plus_dbl, int.class, int.class)); assertTrueVerbose(ts.operatorCanTakeArguments(plus_dbl, double.class, int.class)); }
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: | 134 / 219 |
Version history: | 3 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) |