From: Thomas Walker Lynch Date: Sun, 22 Dec 2024 10:37:31 +0000 (+0000) Subject: split Util to Quantifer and Time X-Git-Url: https://git.reasoningtechnology.com/style/rt_dark_doc.css?a=commitdiff_plain;h=483810c2c0bb74f76e6a8d292b48382a9bf52845;p=Mosaic split Util to Quantifer and Time --- diff --git "a/developer/javac\360\237\226\211/Mosaic_Logger.java" "b/developer/javac\360\237\226\211/Mosaic_Logger.java" index 014d732..1abb5c1 100644 --- "a/developer/javac\360\237\226\211/Mosaic_Logger.java" +++ "b/developer/javac\360\237\226\211/Mosaic_Logger.java" @@ -3,19 +3,13 @@ package com.ReasoningTechnology.Mosaic; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.time.Instant; -import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; - public class Mosaic_Logger{ private static final Logger LOGGER = LoggerFactory.getLogger(Mosaic_Logger.class); - private static final DateTimeFormatter ISO_UTC_FORMATTER = - DateTimeFormatter.ISO_INSTANT.withZone(ZoneOffset.UTC); // Formats and logs an output related to a specific test public static void output(String test_name, String stream, String output_data){ - String timestamp = iso_utc_time(); + String timestamp = Mosaic_Time.iso_UTC_time(); String formatted_log = String.format( "\n%s -----------------------------------------------------------\n" + "Test: %s\n" + @@ -29,7 +23,7 @@ public class Mosaic_Logger{ // Logs a general message for a test public static void message(String test_name, String message){ - String timestamp = iso_utc_time(); + String timestamp = Mosaic_Time.iso_UTC_time(); String formatted_log = String.format( "\n%s -----------------------------------------------------------\n" + "Test: %s\n" + @@ -41,7 +35,7 @@ public class Mosaic_Logger{ } public static void error(String test_name, String message, Throwable error){ - String timestamp = iso_utc_time(); + String timestamp = Mosaic_Time.iso_UTC_time(); String formatted_log = String.format( "\n%s -----------------------------------------------------------\n" + "Test: %s\n" + @@ -55,29 +49,4 @@ public class Mosaic_Logger{ LOGGER.error(formatted_log, error); } - /* - // Logs an error with stack trace - public static void error(String test_name, String message, Throwable error){ - String timestamp = iso_utc_time(); - StringBuilder stack_trace = new StringBuilder(); - for (StackTraceElement element : error.getStackTrace()){ - stack_trace.append(element.toString()).append("\n"); - } - - String formatted_log = String.format( - "\n%s -----------------------------------------------------------\n" + - "Test: %s\n" + - "Message:\n%s\n" + - "Error:\n%s\n", - timestamp, test_name, message, stack_trace - ); - - LOGGER.error(formatted_log); - } - */ - - // Utility to fetch the current time in ISO UTC format - private static String iso_utc_time(){ - return ISO_UTC_FORMATTER.format(Instant.now()); - } } diff --git "a/developer/javac\360\237\226\211/Mosaic_Quantifier.java" "b/developer/javac\360\237\226\211/Mosaic_Quantifier.java" new file mode 100644 index 0000000..493b3c0 --- /dev/null +++ "b/developer/javac\360\237\226\211/Mosaic_Quantifier.java" @@ -0,0 +1,42 @@ +package com.ReasoningTechnology.Mosaic; + +import java.util.function.Predicate; + +public class Mosaic_Quantifier{ + + // Linear search with a predicate + public static T find( T[] elements ,Predicate predicate ){ + for( T element : elements ){ + if( predicate.test( element )) return element; // Return the first match + } + return null; // Return null if no element satisfies the predicate + } + + // True when it does a search and finds a true value; otherwise false. + public static Boolean exists( Object[] elements ){ + return elements.length > 0 && find( elements ,element -> (element instanceof Boolean) && (Boolean) element ) != null; + } + + // True when it does a search and does not find a false value; otherwise false. + // Hence, all true for the empty set is false, which is appropriate for testing. + public static Boolean all( Object[] elements ){ + return elements.length > 0 && find( elements ,element -> !(element instanceof Boolean) || !(Boolean) element ) == null; + } + + public static void all_set_false( Boolean[] condition_list ){ + int i = 0; + while(i < condition_list.length){ + condition_list[i] = false; + i++; + } + } + + public static void all_set_true( Boolean[] condition_list ){ + int i = 0; + while(i < condition_list.length){ + condition_list[i] = true; + i++; + } + } + +} diff --git "a/developer/javac\360\237\226\211/Mosaic_Time.java" "b/developer/javac\360\237\226\211/Mosaic_Time.java" new file mode 100644 index 0000000..6e30236 --- /dev/null +++ "b/developer/javac\360\237\226\211/Mosaic_Time.java" @@ -0,0 +1,13 @@ +package com.ReasoningTechnology.Mosaic; + +import java.time.Instant; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; + +public class Mosaic_Time{ + + public static String iso_UTC_time(){ + return Instant.now().atOffset(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT); + } + +} diff --git "a/developer/javac\360\237\226\211/Mosaic_Util.java" "b/developer/javac\360\237\226\211/Mosaic_Util.java" deleted file mode 100644 index 1fba0cc..0000000 --- "a/developer/javac\360\237\226\211/Mosaic_Util.java" +++ /dev/null @@ -1,50 +0,0 @@ -package com.ReasoningTechnology.Mosaic; - -import java.time.Instant; -import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; -import java.util.function.Predicate; - -public class Mosaic_Util{ - - // Linear search with a predicate - public static T find( T[] elements ,Predicate predicate ){ - for( T element : elements ){ - if( predicate.test( element )) return element; // Return the first match - } - return null; // Return null if no element satisfies the predicate - } - - // True when it does a search and finds a true value; otherwise false. - public static Boolean exists( Object[] elements ){ - return elements.length > 0 && find( elements ,element -> (element instanceof Boolean) && (Boolean) element ) != null; - } - - // True when it does a search and does not find a false value; otherwise false. - public static Boolean all( Object[] elements ){ - return elements.length > 0 && find( elements ,element -> !(element instanceof Boolean) || !(Boolean) element ) == null; - } - - public static void all_set_false( Boolean[] condition_list ){ - int i = 0; - while(i < condition_list.length){ - condition_list[i] = false; - i++; - } - } - - public static void all_set_true( Boolean[] condition_list ){ - int i = 0; - while(i < condition_list.length){ - condition_list[i] = true; - i++; - } - } - - public static String iso_utc_time(){ - return Instant.now().atOffset(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT); - } - - - -} diff --git "a/developer/tool\360\237\226\211/gather_third_party" "b/developer/tool\360\237\226\211/gather_third_party" index e2c9bd9..1e81ace 100755 --- "a/developer/tool\360\237\226\211/gather_third_party" +++ "b/developer/tool\360\237\226\211/gather_third_party" @@ -1,7 +1,7 @@ #!/bin/env bash script_afp=$(realpath "${BASH_SOURCE[0]}") -# This script expands Mosaic third party projects onto the scratchpad. This is done before releasing or running local ad hoc tests, so that the third party tools will be present. +# This script expands Mosaic third party projects onto the scratchpad. This is done before releasing or running local ad hoc tests, so that the third party tools will be present. I.e. this is for creating a 'fat' jar. # Input guards @@ -13,7 +13,7 @@ script_afp=$(realpath "${BASH_SOURCE[0]}") cd "$REPO_HOME"/developer -# Link sources into the package tree +# Expand the third party tools into the package tree echo "Expanding .jar files to be included with Mosaic into scratchpad." diff --git "a/document\360\237\226\211/LICENSE.txt" "b/document\360\237\226\211/LICENSE.txt" new file mode 120000 index 0000000..4ab4373 --- /dev/null +++ "b/document\360\237\226\211/LICENSE.txt" @@ -0,0 +1 @@ +../LICENSE.txt \ No newline at end of file diff --git "a/document\360\237\226\211/README.txt" "b/document\360\237\226\211/README.txt" new file mode 120000 index 0000000..ecfa029 --- /dev/null +++ "b/document\360\237\226\211/README.txt" @@ -0,0 +1 @@ +../README.txt \ No newline at end of file diff --git a/release/Mosaic.jar b/release/Mosaic.jar index 18cae87..f5b1a35 100644 Binary files a/release/Mosaic.jar and b/release/Mosaic.jar differ diff --git "a/tester/javac\360\237\226\211/Dispatcher_0.java" "b/tester/javac\360\237\226\211/Dispatcher_0.java" index 869f6ff..7f4e1f2 100644 --- "a/tester/javac\360\237\226\211/Dispatcher_0.java" +++ "b/tester/javac\360\237\226\211/Dispatcher_0.java" @@ -1,6 +1,6 @@ import com.ReasoningTechnology.Mosaic.Mosaic_Dispatcher; import com.ReasoningTechnology.Mosaic.Mosaic_IsPrimitive; -import com.ReasoningTechnology.Mosaic.Mosaic_Util; +import com.ReasoningTechnology.Mosaic.Mosaic_Quantifier; import tester.TestClasses_0; import tester.TestClasses_1; @@ -34,7 +34,7 @@ public class Dispatcher_0{ public static boolean test_make_0(){ Boolean[] condition_list = new Boolean[4]; - Mosaic_Util.all_set_false(condition_list); + Mosaic_Quantifier.all_set_false(condition_list); int i = 0; Mosaic_Dispatcher d1 = new Mosaic_Dispatcher(TestClasses_1.class); @@ -51,7 +51,7 @@ public class Dispatcher_0{ TestClasses_1 tc3 = (TestClasses_1) d1.make(new Mosaic_IsPrimitive(21) ,new Mosaic_IsPrimitive(17) ); condition_list[i++] = tc3.get_i() == 38; - return Mosaic_Util.all(condition_list); + return Mosaic_Quantifier.all(condition_list); } // Test public static method diff --git "a/tester/javac\360\237\226\211/Dispatcher_1.java" "b/tester/javac\360\237\226\211/Dispatcher_1.java" index 8bd7462..4758510 100644 --- "a/tester/javac\360\237\226\211/Dispatcher_1.java" +++ "b/tester/javac\360\237\226\211/Dispatcher_1.java" @@ -1,5 +1,5 @@ import com.ReasoningTechnology.Mosaic.Mosaic_Dispatcher; -import com.ReasoningTechnology.Mosaic.Mosaic_Util; +import com.ReasoningTechnology.Mosaic.Mosaic_Quantifier; import tester.TestClasses_0; diff --git "a/tester/javac\360\237\226\211/Dispatcher_3.java" "b/tester/javac\360\237\226\211/Dispatcher_3.java" index ca28d1e..e79a1af 100644 --- "a/tester/javac\360\237\226\211/Dispatcher_3.java" +++ "b/tester/javac\360\237\226\211/Dispatcher_3.java" @@ -10,9 +10,9 @@ public class Dispatcher_3{ Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher("tester.TestClasses_0$APrivateClass_02"); Object nested_instance = nested_dispatcher.make(new Object[]{outer_instance}); boolean result = nested_dispatcher.dispatch( - nested_instance , - boolean.class , - "a_public_method_5" + nested_instance + ,boolean.class + ,"a_public_method_5" ); return result; }catch(Throwable t){ @@ -28,9 +28,9 @@ public class Dispatcher_3{ Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher("tester.TestClasses_0$APrivateClass_02"); Object nested_instance = nested_dispatcher.make(new Object[]{outer_instance}); boolean result = nested_dispatcher.dispatch( - nested_instance , - boolean.class , - "a_private_method_6" + nested_instance + ,boolean.class + ,"a_private_method_6" ); return result; }catch(Throwable t){ @@ -46,9 +46,9 @@ public class Dispatcher_3{ TestClasses_0.APublicClass_01 nested_instance = outer.new APublicClass_01(); Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher(TestClasses_0.APublicClass_01.class); boolean result = nested_dispatcher.dispatch( - nested_instance , - boolean.class , - "a_public_method_3" + nested_instance + ,boolean.class + ,"a_public_method_3" ); return result; }catch(Throwable t){ @@ -64,9 +64,9 @@ public class Dispatcher_3{ TestClasses_0.APublicClass_01 nested_instance = outer.new APublicClass_01(); Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher(TestClasses_0.APublicClass_01.class); boolean result = nested_dispatcher.dispatch( - nested_instance , - boolean.class , - "a_private_method_4" + nested_instance + ,boolean.class + ,"a_private_method_4" ); return result; }catch(Throwable t){ diff --git "a/tester/javac\360\237\226\211/IO.java" "b/tester/javac\360\237\226\211/IO.java" index 18e8a8f..5615a09 100644 --- "a/tester/javac\360\237\226\211/IO.java" +++ "b/tester/javac\360\237\226\211/IO.java" @@ -1,5 +1,5 @@ import com.ReasoningTechnology.Mosaic.Mosaic_IO; -import com.ReasoningTechnology.Mosaic.Mosaic_Util; +import com.ReasoningTechnology.Mosaic.Mosaic_Quantifier; public class IO{ @@ -53,7 +53,7 @@ public class IO{ // Restore original IO streams io.restore(); - if(!Mosaic_Util.all(condition)){ + if(!Mosaic_Quantifier.all(condition)){ System.out.println("IO failed"); return 1; } diff --git "a/tester/javac\360\237\226\211/Util.java" "b/tester/javac\360\237\226\211/Util.java" index 210fe71..78e30c9 100644 --- "a/tester/javac\360\237\226\211/Util.java" +++ "b/tester/javac\360\237\226\211/Util.java" @@ -1,4 +1,4 @@ -import com.ReasoningTechnology.Mosaic.Mosaic_Util; +import com.ReasoningTechnology.Mosaic.Mosaic_Quantifier; /* Util @@ -10,23 +10,23 @@ public class Util{ public static Boolean test_all(){ // Test with zero condition Boolean[] condition0 = {}; - Boolean result = !Mosaic_Util.all(condition0); // Empty condition list is false. + Boolean result = !Mosaic_Quantifier.all(condition0); // Empty condition list is false. // Test with one condition Boolean[] condition1_true = {true}; Boolean[] condition1_false = {false}; - result &= Mosaic_Util.all(condition1_true); // should return true - result &= !Mosaic_Util.all(condition1_false); // should return false + result &= Mosaic_Quantifier.all(condition1_true); // should return true + result &= !Mosaic_Quantifier.all(condition1_false); // should return false // Test with two condition Boolean[] condition2_true = {true, true}; Boolean[] condition2_false1 = {true, false}; Boolean[] condition2_false2 = {false, true}; Boolean[] condition2_false3 = {false, false}; - result &= Mosaic_Util.all(condition2_true); // should return true - result &= !Mosaic_Util.all(condition2_false1); // should return false - result &= !Mosaic_Util.all(condition2_false2); // should return false - result &= !Mosaic_Util.all(condition2_false3); // should return false + result &= Mosaic_Quantifier.all(condition2_true); // should return true + result &= !Mosaic_Quantifier.all(condition2_false1); // should return false + result &= !Mosaic_Quantifier.all(condition2_false2); // should return false + result &= !Mosaic_Quantifier.all(condition2_false3); // should return false // Test with three condition Boolean[] condition3_false1 = {true, true, false}; @@ -34,24 +34,24 @@ public class Util{ Boolean[] condition3_false2 = {true, false, true}; Boolean[] condition3_false3 = {false, true, true}; Boolean[] condition3_false4 = {false, false, false}; - result &= !Mosaic_Util.all(condition3_false1); // should return false - result &= Mosaic_Util.all(condition3_true); // should return true - result &= !Mosaic_Util.all(condition3_false2); // should return false - result &= !Mosaic_Util.all(condition3_false3); // should return false - result &= !Mosaic_Util.all(condition3_false4); // should return false + result &= !Mosaic_Quantifier.all(condition3_false1); // should return false + result &= Mosaic_Quantifier.all(condition3_true); // should return true + result &= !Mosaic_Quantifier.all(condition3_false2); // should return false + result &= !Mosaic_Quantifier.all(condition3_false3); // should return false + result &= !Mosaic_Quantifier.all(condition3_false4); // should return false return result; } public static Boolean test_all_set_false(){ Boolean[] condition_list = {true, true, true}; - Mosaic_Util.all_set_false(condition_list); + Mosaic_Quantifier.all_set_false(condition_list); return !condition_list[0] && !condition_list[1] && !condition_list[2]; } public static Boolean test_all_set_true(){ Boolean[] condition_list = {false, false, false}; - Mosaic_Util.all_set_true(condition_list); + Mosaic_Quantifier.all_set_true(condition_list); return condition_list[0] && condition_list[1] && condition_list[2]; } diff --git "a/tester/javac\360\237\226\211/smoke.java" "b/tester/javac\360\237\226\211/smoke.java" index ccfc75e..567b8f6 100644 --- "a/tester/javac\360\237\226\211/smoke.java" +++ "b/tester/javac\360\237\226\211/smoke.java" @@ -1,4 +1,4 @@ -import com.ReasoningTechnology.Mosaic.Mosaic_Util; +import com.ReasoningTechnology.Mosaic.Mosaic_Quantifier; /* Plug it in, see if there is smoke. There usually is. @@ -16,7 +16,7 @@ public class smoke{ condition[0] = test_is_true(); int i = 0; - if( !Mosaic_Util.all(condition) ){ + if( !Mosaic_Quantifier.all(condition) ){ System.out.println("Test0 failed"); return 1; } diff --git "a/tester/tool\360\237\226\211/run_jdb" "b/tester/tool\360\237\226\211/run_jdb" deleted file mode 100755 index 8334c1b..0000000 --- "a/tester/tool\360\237\226\211/run_jdb" +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/env bash -script_afp=$(realpath "${BASH_SOURCE[0]}") - -# input guards -env_must_be="tester/tool🖉/env" -if [ "$ENV" != "$env_must_be" ]; then - echo "$(script_fp):: error: must be run in the $env_must_be environment" - exit 1 -fi - -jdb -sourcepath "$SOURCEPATH" "$@" -