feat: add Example for HaskellStyle Pattern Matching
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 42s

This commit is contained in:
Ruben 2024-10-25 12:06:23 +02:00
parent cc204f659a
commit 4d1950d0ba
2 changed files with 25 additions and 2 deletions

View File

@ -9,6 +9,6 @@ public class PaternMatchingHaskellStyle {
} }
public append(LinkedElem(a, r), l2) { public append(LinkedElem(a, r), l2) {
new LinkedElem<>(a, append(r, l2)); return new LinkedElem<>(a, append(r, l2));
} }
} }

View File

@ -854,6 +854,29 @@ public class TestComplete {
assertEquals(m2.invoke(instance, 10), 10); assertEquals(m2.invoke(instance, 10), 10);
} }
@Ignore("Not implemented")
@Test
public void testOverloadPatternMatching() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "PaternMatchingHaskellStyle.jav");
var clazz = classFiles.get("PaternMatchingHaskellStyle");
var R2 = classFiles.get("Elem");
var R = classFiles.get("LinkedElem");
var I = classFiles.get("List");
var rctor = R.getDeclaredConstructor(Object.class, I);
var r2ctor = R2.getDeclaredConstructor(Object.class);
var instance = clazz.getDeclaredConstructor().newInstance();
var m = clazz.getDeclaredMethod("append", R, I);
//var x = rctor.newInstance(rctor.newInstance(0, rctor.newInstance(0, r2ctor.newInstance(0))), 0);
//var y = rctor.newInstance(r2ctor.newInstance(0), 0);
//assertEquals(m.invoke(instance, x, y), 10);
//assertEquals(m.invoke(instance, y, y), 40.0);
}
@Test @Test
public void testOverloadSwitch() throws Exception { public void testOverloadSwitch() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "SwitchOverload.jav"); var classFiles = generateClassFiles(new ByteArrayClassLoader(), "SwitchOverload.jav");
@ -868,7 +891,7 @@ public class TestComplete {
var x = rctor.newInstance(10); var x = rctor.newInstance(10);
var d = rctor.newInstance(20.0); var d = rctor.newInstance(20.0);
assertEquals(m.invoke(instance, x, 0), 50); assertEquals(m.invoke(instance, x, 0), 10);
assertEquals(m.invoke(instance, d, 0), 40.0); assertEquals(m.invoke(instance, d, 0), 40.0);
} }