diff --git a/src/main/bundles/prod.bundle b/src/main/bundles/prod.bundle index d10789f..1f34d4d 100644 Binary files a/src/main/bundles/prod.bundle and b/src/main/bundles/prod.bundle differ diff --git a/src/main/java/com/primefactorsolutions/service/CompilerService.java b/src/main/java/com/primefactorsolutions/service/CompilerService.java index f1440cd..43b8608 100644 --- a/src/main/java/com/primefactorsolutions/service/CompilerService.java +++ b/src/main/java/com/primefactorsolutions/service/CompilerService.java @@ -1,6 +1,5 @@ package com.primefactorsolutions.service; -import com.primefactorsolutions.service.compiler.InMemoryClass; import com.primefactorsolutions.service.compiler.InMemoryFileManager; import com.primefactorsolutions.service.compiler.JavaSourceFromString; import lombok.SneakyThrows; @@ -11,6 +10,7 @@ import javax.tools.DiagnosticCollector; import javax.tools.JavaCompiler; import javax.tools.JavaFileObject; import javax.tools.ToolProvider; +import java.lang.reflect.Method; import java.util.Collections; import java.util.List; import java.util.Map; @@ -44,8 +44,15 @@ public class CompilerService { } else { final ClassLoader classLoader = manager.getClassLoader(null); final Class clazz = classLoader.loadClass(qualifiedClassName); - final InMemoryClass instanceOfClass = (InMemoryClass) clazz.newInstance(); - final Map results = instanceOfClass.runCode(); + Map results = Map.of(); + + Method[] methods = clazz.getMethods(); + for (Method m : methods) { + if ("run".equals(m.getName())) { + results = (Map) m.invoke(null, new Object[] {}); + break; + } + } return Optional.of(results.entrySet().stream() .map(e -> String.format("%-50s ... %4s", e.getKey(), RESULT_MESSAGE.get(e.getValue()))) diff --git a/src/main/java/com/primefactorsolutions/views/EvaluationView.java b/src/main/java/com/primefactorsolutions/views/EvaluationView.java index 401d9dc..219a893 100644 --- a/src/main/java/com/primefactorsolutions/views/EvaluationView.java +++ b/src/main/java/com/primefactorsolutions/views/EvaluationView.java @@ -301,13 +301,12 @@ public class EvaluationView extends Main implements HasUrlParameter { questionEditor.setSofttabs(true); questionEditor.setTabSize(4); questionEditor.setWrap(true); - questionEditor.setMinlines(20); - questionEditor.setMaxlines(30); - // aceEditor.setPlaceholder("... Edit ..."); - questionEditor.setAutoComplete(true); - questionEditor.setCustomAutoCompletion(new String[] { "TEST", "TEST2", "TEST3" }); + questionEditor.setMinlines(60); + questionEditor.setMaxlines(80); + questionEditor.setAutoComplete(false); questionEditor.setHighlightActiveLine(true); questionEditor.setHighlightSelectedWord(false); + return questionEditor; } diff --git a/src/main/resources/questions/fibonaci.java.txt b/src/main/resources/questions/fibonaci.java.txt index 037876c..9b91c46 100644 --- a/src/main/resources/questions/fibonaci.java.txt +++ b/src/main/resources/questions/fibonaci.java.txt @@ -1,11 +1,10 @@ package com.primefactorsolutions; -import com.primefactorsolutions.service.compiler.InMemoryClass; import java.util.*; import java.lang.reflect.*; import java.util.stream.Collectors; -public class TestClass implements InMemoryClass { +public class TestClass { // ------------ IMPLEMENTAR AQUI -------------------------------- @@ -37,8 +36,7 @@ public class TestClass implements InMemoryClass { } } - @Override - public Map runCode() { + public static Map run() { Map results = Arrays.stream(Tests.class.getDeclaredMethods()) .map(m -> { try { diff --git a/src/main/resources/questions/foobar.java.txt b/src/main/resources/questions/foobar.java.txt new file mode 100644 index 0000000..cd1e81d --- /dev/null +++ b/src/main/resources/questions/foobar.java.txt @@ -0,0 +1,46 @@ +package com.primefactorsolutions; + +import java.util.*; +import java.lang.reflect.*; +import java.util.stream.Collectors; + +public class TestClass { + + // ------------ IMPLEMENTAR AQUI -------------------------------- + + public static String getFooBar(int N) { + return "TODO"; + } + + + // ------------- NO MODIFICAR DESDE ESTA LINEA -------------------- + + public static class Tests { + public static Map.Entry testNInvalido() { + boolean result = getFooBar(-1).equals(""); + + return Map.entry("N invalido retorna vacio", result); + } + + public static Map.Entry testNValido() { + boolean result = getFooBar(7).equals("1,Foo,Bar,Foo,5,FooBar,7"); + + return Map.entry("N valido correcto", result); + } + } + + public static Map run() { + Map results = Arrays.stream(Tests.class.getDeclaredMethods()) + .map(m -> { + try { + return (Map.Entry) m.invoke(null); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } + }).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())); + + return results; + } +} \ No newline at end of file diff --git a/src/main/resources/questions/palindroma.java.txt b/src/main/resources/questions/palindroma.java.txt index b1462d1..601c837 100644 --- a/src/main/resources/questions/palindroma.java.txt +++ b/src/main/resources/questions/palindroma.java.txt @@ -1,11 +1,10 @@ package com.primefactorsolutions; -import com.primefactorsolutions.service.compiler.InMemoryClass; import java.util.*; import java.lang.reflect.*; import java.util.stream.Collectors; -public class TestClass implements InMemoryClass { +public class TestClass { // ------------ IMPLEMENTAR AQUI -------------------------------- @@ -30,9 +29,15 @@ public class TestClass implements InMemoryClass { } public static Map.Entry testPalindromaUnico() { - boolean result = getPalindroma("z").equals("ZZ"); + boolean result = getPalindroma("z").equals("Z"); - return Map.entry("palindrome una solo caracter es valido", result); + return Map.entry("palindrome un solo caracter es valido", result); + } + + public static Map.Entry testPalindromaUnico() { + boolean result = getPalindroma("abba").equals("ABBA"); + + return Map.entry("palindrome un solo caracter es valido", result); } public static Map.Entry testPalindromaNull() { @@ -42,8 +47,7 @@ public class TestClass implements InMemoryClass { } } - @Override - public Map runCode() { + public static Map run() { Map results = Arrays.stream(Tests.class.getDeclaredMethods()) .map(m -> { try {