From 49031580021815731c9c9bc4945e329a59340d17 Mon Sep 17 00:00:00 2001 From: Diego Sevilla Ruiz Date: Thu, 22 Feb 2024 22:35:36 +0100 Subject: [PATCH] No Jscheme. --- .../grpc/impl/jscheme/JSchemeProvider.java | 40 ------ .../grpc/impl/jscheme/MapReduceApply.java | 116 ------------------ .../grpc/impl/jscheme/MapperApply.java | 85 ------------- .../grpc/impl/jscheme/ReducerApply.java | 44 ------- .../grpc/impl/jsexample/JSchemeExample.java | 90 -------------- .../jscheme/test/MapReduceSimpleTest.java | 104 ---------------- .../jscheme/test/MapReduceWordCountTest.java | 109 ---------------- .../impl/jscheme/test/MapperApplyTest.java | 77 ------------ .../impl/jscheme/test/ReducerApplyTest.java | 54 -------- 9 files changed, 719 deletions(-) delete mode 100644 proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jscheme/JSchemeProvider.java delete mode 100644 proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jscheme/MapReduceApply.java delete mode 100644 proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jscheme/MapperApply.java delete mode 100644 proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jscheme/ReducerApply.java delete mode 100644 proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jsexample/JSchemeExample.java delete mode 100644 proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/tests/java/tests/es/um/sisdist/backend/grpc/impl/jscheme/test/MapReduceSimpleTest.java delete mode 100644 proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/tests/java/tests/es/um/sisdist/backend/grpc/impl/jscheme/test/MapReduceWordCountTest.java delete mode 100644 proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/tests/java/tests/es/um/sisdist/backend/grpc/impl/jscheme/test/MapperApplyTest.java delete mode 100644 proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/tests/java/tests/es/um/sisdist/backend/grpc/impl/jscheme/test/ReducerApplyTest.java diff --git a/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jscheme/JSchemeProvider.java b/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jscheme/JSchemeProvider.java deleted file mode 100644 index 0cea827..0000000 --- a/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jscheme/JSchemeProvider.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * - */ -package es.um.sisdist.backend.grpc.impl.jscheme; - -import jscheme.JScheme; - -/** - * @author dsevilla - * - */ -public class JSchemeProvider -{ - public static JScheme js() - { - JScheme js_instance = new JScheme(); - // Useful code - js_instance.load( - "(define (filter f lst)\n" - + " (define (iter lst result)\n" - + " (cond\n" - + " ((null? lst) (reverse result))\n" - + " ((f (car lst)) (iter (cdr lst)\n" - + " (cons (car lst) result)))\n" - + " (else (iter (cdr lst)\n" - + " result))))\n" - + " (iter lst '()))\n" - + "(define (reduce fn list init)" - + " (if (null? list) init" - + " (fn (car list)" - + " (reduce fn (cdr list) init))))" - + "(define (map f L)" - + " (if (null? L)" - + " ()\n" - + " (cons (f (car L))" - + " (map f (cdr L)))))" - ); - return js_instance; - } -} diff --git a/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jscheme/MapReduceApply.java b/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jscheme/MapReduceApply.java deleted file mode 100644 index 68602a4..0000000 --- a/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jscheme/MapReduceApply.java +++ /dev/null @@ -1,116 +0,0 @@ -package es.um.sisdist.backend.grpc.impl.jscheme; - -import static jscheme.JScheme.list; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import jscheme.JScheme; -import jscheme.SchemePair; -import jsint.Pair; - -/** - * - * @author dsevilla - * - * La clase MappReduceApply recibe un entorno de ejecución JScheme, una función map - * como una cadena de caracteres, una función reduce como una cadena de caracteres y produce - * un array resultado como un diccionario (Map) que mapea claves y valores. Para cada par - * de entrada, hay que llamar a la función apply, que irá generando el mapa de shuffle. - * Para realizar el map-reduce, hay que llamar a la función map-reduce(). - */ -public class MapReduceApply -{ - private String ssdd_map_function = null; - private String ssdd_reduce_function = null; - - static private SchemePair list_to_pair(List l) - { - if (l.isEmpty()) - return list(); - return list_to_pair_aux(l.iterator()); - } - - static private SchemePair list_to_pair_aux(Iterator it) - { - if (!it.hasNext()) - return list(); - Object next = it.next(); - if (!it.hasNext()) - return new Pair(next, list()); - else - return new Pair(next, list_to_pair_aux(it)); - } - - private JScheme js = null; - - MapperApply ma; - ReducerApply ra; - Map> shuffle_map; - Map result; - - private void _install_emit_map_reduce_functions() - { - // Mapper - ma = new MapperApply(js, ssdd_map_function, - p -> // emit function - { - var l = shuffle_map.getOrDefault(p.first(), new LinkedList<>()); - l.add(p.second()); - shuffle_map.putIfAbsent(p.first(), l); - return null; - }); - // Reducer - ra = new ReducerApply(js, ssdd_reduce_function); - } - - public MapReduceApply(JScheme js, String scheme_map_function, String scheme_reduce_function) - { - super(); - this.shuffle_map = new HashMap<>(); - this.result = new HashMap<>(); - this.ssdd_map_function = scheme_map_function; - this.ssdd_reduce_function = scheme_reduce_function; - this.js = js; - _install_emit_map_reduce_functions(); - } - - public void apply(T1 k, T2 v) - { - ma.apply(k, v); - } - - public Map map_reduce() - { - shuffle_map.entrySet().forEach(e -> - { - Object res = ra.apply(e.getKey(), list_to_pair(e.getValue())); - result.put(e.getKey(), res); - }); - - return result; - } - - public String getScheme_ssdd_map_function() { - return ssdd_map_function; - } - public void setScheme_ssdd_map_function(String scheme_map_function) { - this.ssdd_map_function = scheme_map_function; - _install_emit_map_reduce_functions(); - } - - public String getSsdd_reduce_function() { - return ssdd_reduce_function; - } - - public void setSsdd_reduce_function(String ssdd_reduce_function) { - this.ssdd_reduce_function = ssdd_reduce_function; - _install_emit_map_reduce_functions(); - } - - public JScheme getJs() { - return js; - } -} diff --git a/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jscheme/MapperApply.java b/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jscheme/MapperApply.java deleted file mode 100644 index 40afd83..0000000 --- a/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jscheme/MapperApply.java +++ /dev/null @@ -1,85 +0,0 @@ -package es.um.sisdist.backend.grpc.impl.jscheme; - -import java.util.function.Function; - -import jscheme.JScheme; -import jscheme.SchemePair; -import jsint.Procedure; - -/** - * - * @author dsevilla - * - * La clase MapperApply recibe un entorno de ejecución JScheme, una función map - * como una cadena de caracteres y opcionalmente una función emit que se conecta - * con el intérprete JScheme para ser llamada cada vez que el código de la función - * map realice un emit. - */ -public class MapperApply -{ - private static Void nilfunc(SchemePair p) {return null;}; - - private String ssdd_map_function = null; - private Function emit_function = MapperApply::nilfunc; - private JScheme js = null; - - private void _install_emit_map_functions() - { - var p = new Procedure() { - private static final long serialVersionUID = 6988405761033921572L; - - @Override - public Object apply(Object[] arg0) - { - SchemePair arg = (SchemePair)((SchemePair)arg0[0]).first(); - emit_function.apply(arg); - System.out.println("Key: " + arg.first() + ". Value: " + - arg.second()); - return null; - } - }; - p.setName("emit"); - js.setGlobalValue("emit", p); - - // ssdd-map - js.load(ssdd_map_function); - } - - public MapperApply(JScheme js, String scheme_map_function) - { - super(); - this.ssdd_map_function = scheme_map_function; - this.js = js; - - } - public MapperApply(JScheme js, String scheme_map_function, Function emit_function) - { - super(); - this.ssdd_map_function = scheme_map_function; - this.emit_function = emit_function; - this.js = js; - _install_emit_map_functions(); - } - - public void apply(T1 k, T2 v) - { - js.call("ssdd-map", k, v); - } - - public String getScheme_ssdd_map_function() { - return ssdd_map_function; - } - public void setScheme_ssdd_map_function(String scheme_map_function) { - this.ssdd_map_function = scheme_map_function; - } - public Function getEmit_function() { - return emit_function; - } - public void setEmit_function(Function emit_function) { - this.emit_function = emit_function; - _install_emit_map_functions(); - } - public JScheme getJs() { - return js; - } -} diff --git a/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jscheme/ReducerApply.java b/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jscheme/ReducerApply.java deleted file mode 100644 index 9cf0108..0000000 --- a/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jscheme/ReducerApply.java +++ /dev/null @@ -1,44 +0,0 @@ -package es.um.sisdist.backend.grpc.impl.jscheme; - -import jscheme.JScheme; -import jscheme.SchemePair; - -/** - * - * @author dsevilla - * - */ -public class ReducerApply -{ - private JScheme js = null; - private String ssdd_reduce_function = null; - - private void _install_reduce_function() - { - // ssdd_reduce - js.load(ssdd_reduce_function); - } - - public ReducerApply(JScheme js, String scheme_reduce_function) - { - super(); - this.ssdd_reduce_function = scheme_reduce_function; - this.js = js; - _install_reduce_function(); - } - - public Object apply(T1 e1, SchemePair e2) - { - return js.call("ssdd-reduce", e1, e2); - } - - public String getScheme_ssdd_map_function() { - return ssdd_reduce_function; - } - public void setScheme_ssdd_map_function(String scheme_reduce_function) { - this.ssdd_reduce_function = scheme_reduce_function; - } - public JScheme getJs() { - return js; - } -} diff --git a/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jsexample/JSchemeExample.java b/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jsexample/JSchemeExample.java deleted file mode 100644 index 6ac4776..0000000 --- a/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/src/es/um/sisdist/backend/grpc/impl/jsexample/JSchemeExample.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * - */ -package es.um.sisdist.backend.grpc.impl.jsexample; - -import jscheme.JScheme; -import jscheme.SchemePair; - -import static jscheme.JScheme.*; - -import java.io.FileNotFoundException; - -import jsint.Procedure; - -/** - * @author dsevilla - * - */ -public class JSchemeExample -{ - public static void main(String[] args) throws FileNotFoundException - { - JScheme js = new JScheme(); - js.load("(define (countdown x)\n" - + " (define (loop x acc)\n" - + " (if (= x 0)\n" - + " acc\n" - + " (loop (- x 1) (+ acc x))))\n" - + " (loop x 0))\n" - + "\n" - + "(define (retlength l) (length l))\n" - + ";;; config variables\n" - + "(define msg \"Hello from JScheme!\")\n" - + ";; tail calls are optimized as required\n" - + "(define answer (countdown 42))\n" - ); - // load useful code - js.load("(define (filter f lst)\n" - + " (define (iter lst result)\n" - + " (cond\n" - + " ((null? lst) (reverse result))\n" - + " ((f (car lst)) (iter (cdr lst)\n" - + " (cons (car lst) result)))\n" - + " (else (iter (cdr lst)\n" - + " result))))\n" - + " (iter lst '()))\n" - + "(define (reduce fn list init)\n" - + " (if (null? list) init" - + " (fn (car list)" - + " (reduce fn (cdr list) init))))" - + "(define (map f L)" - + " (if (null? L)" - + " ()\n" - + " (cons (f (car L))" - + " (map f (cdr L)))))" - ); - - System.out.println("Message: '" + js.eval("msg") + "'"); - - // Values - int answer = (Integer) js.eval("answer"); - - System.out.println("Answer: " + answer); - - // Function calls - System.out.println(js.call("countdown", 42)); - System.out.println("Length: " + js.call("retlength", list(1,2))); - Procedure p = new Procedure() - { - private static final long serialVersionUID = 6988405761033921572L; - - @Override - public Object apply(Object[] arg0) - { - SchemePair arg = (SchemePair)((SchemePair)arg0[0]).first(); - System.out.println("Key: " + arg.first() - + ". Value: " + arg.second() - ); - return null; - } - }; - p.setName("emit"); - js.setGlobalValue("a" , 2); - js.setGlobalValue("emit", p); - - System.out.println("Emit '(1 2): " + js.call("emit", list(1,2))); - - js.readEvalPrintLoop(); - } -} diff --git a/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/tests/java/tests/es/um/sisdist/backend/grpc/impl/jscheme/test/MapReduceSimpleTest.java b/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/tests/java/tests/es/um/sisdist/backend/grpc/impl/jscheme/test/MapReduceSimpleTest.java deleted file mode 100644 index 6f3e555..0000000 --- a/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/tests/java/tests/es/um/sisdist/backend/grpc/impl/jscheme/test/MapReduceSimpleTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/** - * - */ -package es.um.sisdist.backend.grpc.impl.jscheme.test; - -import static org.junit.jupiter.api.Assertions.*; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import static java.util.stream.Collectors.*; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import es.um.sisdist.backend.grpc.impl.jscheme.JSchemeProvider; -import es.um.sisdist.backend.grpc.impl.jscheme.MapReduceApply; - -import static jscheme.JScheme.*; -import jscheme.JScheme; -import jscheme.SchemePair; - -/** - * @author dsevilla - * - */ -class MapReduceSimpleTest -{ - static JScheme js; - - public static void main(String[] args) - { - try { - setUpBeforeClass(); - } catch (Exception e) { - e.printStackTrace(); - } - new MapReduceSimpleTest().test(); - } - - /** - * @throws java.lang.Exception - */ - @BeforeAll - static void setUpBeforeClass() throws Exception - { - js = JSchemeProvider.js(); - } - - /** - * @throws java.lang.Exception - */ - @BeforeEach - void setUp() throws Exception { - } - - @Test - void test() - { - // Mapper - MapReduceApply mar = new MapReduceApply(js, - "(define (ssdd-map k v)" // Función identidad - + " (emit (list k v)))", - - // Función reduce - "(define (ssdd-reduce k l)" - + " (apply + l))"); - - List values = Arrays.asList( - list(1,1), - list(1,3), - list(1,3), - list(2,3), - list(2,3) - ); - - values.stream().forEach(p -> mar.apply(p.first(), p.second())); - - // 1 -> (1 3 3) -> 7 - // 2 -> (3 3) -> 6 - - // Reducer - Map result = mar.map_reduce(); - - // Aplicar el mismo procesamiento en la lista java - var result_java = values.stream().collect( - groupingBy(SchemePair::first, - reducing(0, - p -> (Integer)p.second(), // mapping - (p1,p2) -> { - return (Integer)p1 + (Integer)p2; - })) - ); - - result_java.entrySet().forEach(e -> { - Object p = result.get(e.getKey()); - assertNotNull(p); - assertEquals(e.getValue(), p); - }); - - System.out.println("Done"); - } -} diff --git a/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/tests/java/tests/es/um/sisdist/backend/grpc/impl/jscheme/test/MapReduceWordCountTest.java b/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/tests/java/tests/es/um/sisdist/backend/grpc/impl/jscheme/test/MapReduceWordCountTest.java deleted file mode 100644 index 5b6414e..0000000 --- a/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/tests/java/tests/es/um/sisdist/backend/grpc/impl/jscheme/test/MapReduceWordCountTest.java +++ /dev/null @@ -1,109 +0,0 @@ -/** - * - */ -package es.um.sisdist.backend.grpc.impl.jscheme.test; - -import static org.junit.jupiter.api.Assertions.*; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import static java.util.stream.Collectors.*; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import es.um.sisdist.backend.grpc.impl.jscheme.JSchemeProvider; -import es.um.sisdist.backend.grpc.impl.jscheme.MapReduceApply; - -import static jscheme.JScheme.*; -import jscheme.JScheme; -import jscheme.SchemePair; - -/** - * @author dsevilla - * - */ -class MapReduceWordCountTest -{ - static JScheme js; - - public static void main(String[] args) - { - try { - setUpBeforeClass(); - } catch (Exception e) { - e.printStackTrace(); - } - new MapReduceWordCountTest().test(); - } - /** - * @throws java.lang.Exception - */ - @BeforeAll - static void setUpBeforeClass() throws Exception - { - js = JSchemeProvider.js(); - } - - /** - * @throws java.lang.Exception - */ - @BeforeEach - void setUp() throws Exception { - } - - @Test - void test() - { - List values = Arrays.asList( - list(1,"abc def ghi"), - list(2,"abc def thi"), - list(3,"abc def xhi"), - list(4,"abc def rhi"), - list(5,"abc def jhi") - ); - - // Mapper - MapReduceApply mar = new MapReduceApply(js, - - // Función map - "(import \"java.lang.String\")" - + "(define (ssdd-map k v)" - + " (display k)" - + " (display \": \")" - + " (display v)" - + " (display \"\\n\")" - + " (for-each (lambda (w)" - + " (emit (list w 1)))" - + " (vector->list (.split v \" \"))))", - - // Función reduce - "(define (ssdd-reduce k l)" + - " (apply + l))"); - - values.stream().forEach(p -> mar.apply(p.first(), p.second())); - - Map result = mar.map_reduce(); - - // Aplicar el mismo procesamiento en la lista java - var result_java = values.stream().flatMap(p -> - Arrays.asList(((String)p.second()).split(" ")).stream()) - .map(w -> list(w,1)) - .collect( - groupingBy(SchemePair::first, - reducing(0, - p -> (Integer)p.second(), // mapping - (p1,p2) -> (Integer)p1 + (Integer)p2)) - ); - - result_java.entrySet().forEach(e -> { - Object v = result.get(e.getKey()); - assertNotNull(v); - assertEquals(e.getValue(), v); - }); - - System.out.println("Done"); - } -} diff --git a/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/tests/java/tests/es/um/sisdist/backend/grpc/impl/jscheme/test/MapperApplyTest.java b/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/tests/java/tests/es/um/sisdist/backend/grpc/impl/jscheme/test/MapperApplyTest.java deleted file mode 100644 index 38e112b..0000000 --- a/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/tests/java/tests/es/um/sisdist/backend/grpc/impl/jscheme/test/MapperApplyTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * - */ -package es.um.sisdist.backend.grpc.impl.jscheme.test; - -import static org.junit.jupiter.api.Assertions.*; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import es.um.sisdist.backend.grpc.impl.jscheme.JSchemeProvider; -import es.um.sisdist.backend.grpc.impl.jscheme.MapperApply; -import jscheme.JScheme; - -/** - * @author dsevilla - * - */ -class MapperApplyTest -{ - static JScheme js; - - static class Wrap { - int v = 0; - - void inc() {++v;} - int get() {return v;} - }; - - /** - * @throws java.lang.Exception - */ - @BeforeAll - static void setUpBeforeClass() throws Exception - { - js = JSchemeProvider.js(); - } - - /** - * @throws java.lang.Exception - */ - @BeforeEach - void setUp() throws Exception { - } - - /** - * Test method - */ - @Test - void testApply_map_function() - { - final Wrap w = new Wrap(); - - MapperApply ma = new MapperApply(js, - "(define (ssdd-map k v)" - + " (display k)" - + " (display \": \")" - + " (display v)" - + " (emit (list k v)))", - p -> // emit function - { - System.out.println("Called: " - + p.first() - + ", " - + p.second()); - w.inc(); - return null; - }); - - ma.apply(3, 4); - assertEquals(w.get(), 1); - - ma.apply("a", "b"); - assertEquals(w.get(), 2); - } -} diff --git a/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/tests/java/tests/es/um/sisdist/backend/grpc/impl/jscheme/test/ReducerApplyTest.java b/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/tests/java/tests/es/um/sisdist/backend/grpc/impl/jscheme/test/ReducerApplyTest.java deleted file mode 100644 index f5bf833..0000000 --- a/proyecto/backend-grpc/es.um.sisdist.backend.grpc.GrpcServiceImpl/tests/java/tests/es/um/sisdist/backend/grpc/impl/jscheme/test/ReducerApplyTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * - */ -package es.um.sisdist.backend.grpc.impl.jscheme.test; - -import static jscheme.JScheme.list; -import static org.junit.jupiter.api.Assertions.*; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import es.um.sisdist.backend.grpc.impl.jscheme.JSchemeProvider; -import es.um.sisdist.backend.grpc.impl.jscheme.ReducerApply; -import jscheme.JScheme; - -/** - * @author dsevilla - * - */ -class ReducerApplyTest -{ - static JScheme js; - - /** - * @throws java.lang.Exception - */ - @BeforeAll - static void setUpBeforeClass() throws Exception - { - js = JSchemeProvider.js(); - } - - /** - * @throws java.lang.Exception - */ - @BeforeEach - void setUp() throws Exception { - } - - @Test - void test() - { - ReducerApply ra = new ReducerApply(js, - "(define (ssdd-reduce k l)" - + " (reduce + l 0))"); - - assertEquals(14, - ra.apply(3 , list(4,10))); - - assertEquals(21, - ra.apply(24, list(1,2,3, 4, 5, 6))); - } -}