From 6a08643ccf00dc9e44c2132592136bc719f35519 Mon Sep 17 00:00:00 2001 From: abuts Date: Sun, 22 Dec 2024 13:39:58 +0000 Subject: [PATCH] Re #1790 minor changes to finish hashable --- _test/common_functions/hashable_obj_tester.m | 22 ++++++++-- .../utilities/classes/@serializable/eq.m | 28 ------------ .../classes/@serializable/private/eq_.m | 44 ------------------- 3 files changed, 18 insertions(+), 76 deletions(-) delete mode 100644 herbert_core/utilities/classes/@serializable/eq.m delete mode 100644 herbert_core/utilities/classes/@serializable/private/eq_.m diff --git a/_test/common_functions/hashable_obj_tester.m b/_test/common_functions/hashable_obj_tester.m index 35f5889f58..7756204d02 100644 --- a/_test/common_functions/hashable_obj_tester.m +++ b/_test/common_functions/hashable_obj_tester.m @@ -6,13 +6,23 @@ function hashable_obj_tester(hobj,values,names) % and hash is stored-restored correctly % % Inputs: -% hobj -- instance of hashable object, better with proper values set +% hobj -- instance of hashable object, with proper values set to +% its properties. hobj build with empty constructor may not be +% acceptable. % Optional % values-- cellarray of values to set to hashable object. If present, have % to have number of elements equal to number of hashable % properties and values of this properties compartible with % serializeble, i.e. setting property do not contradict to other -% properties, validated through check_combo_arg method +% properties, validated through check_combo_arg method. +% If missing, will use current values of hashable properties. +% +% Majority of hashable objects do not verify if input property +% value have changed from its current value and invalidate hash +% anyway. Small subset of hashable objects do check if properties +% chanded so they need these valus different from the values +% already set in the input hobj. +% % names -- list of the properties to set to check hashable object. % If missing, use hashableFields % @@ -42,15 +52,19 @@ function hashable_obj_tester(hobj,values,names) hobj = hobj.build_hash(); end +% check if hobj converts into serizliable structure S = hobj.to_struct(); -rec_obj= hobj.from_struct(S); +% and can be successfuly restored back from it, keeping hash intact +rec_obj= hashable.from_struct(S); assertTrue(hobj.hash_defined); assertTrue(hobj == rec_obj) obj_arr = [hobj,hobj]; +% check if array of hobj converts into serizliable structure S = obj_arr.to_struct(); -rec_arr= hobj.from_struct(S); +% and can be successfuly restored back from it, keeping hash intact +rec_arr= hashable.from_struct(S); assertTrue(rec_arr.hash_defined); assertTrue(obj_arr == rec_arr) \ No newline at end of file diff --git a/herbert_core/utilities/classes/@serializable/eq.m b/herbert_core/utilities/classes/@serializable/eq.m deleted file mode 100644 index 90097930f4..0000000000 --- a/herbert_core/utilities/classes/@serializable/eq.m +++ /dev/null @@ -1,28 +0,0 @@ -function [iseq, mess] = eq (obj1, obj2, varargin) -% Return a logical variable stating if two serializable objects are equal or not -% -% >> [iseq, mess] = eq (obj1, obj2) -% >> [iseq, mess] = eq (obj1, obj2, p1, p2, ...) -% -% Input: -% ------ -% obj1 Object on left-hand side -% -% obj2 Object on right-hand side -% -% Optional: -% p1, p2,... Any set of parameters that the equal_to_tol function accepts -% -% See also equal_to_tol - - -names = cell(2,1); -if nargout == 2 - names{1} = inputname(1); - names{2} = inputname(2); - [iseq, mess] = eq_ (obj1, obj2, nargout, names, varargin{:}); -else - iseq = eq_ (obj1, obj2, nargout, names, varargin{:}); -end - -end diff --git a/herbert_core/utilities/classes/@serializable/private/eq_.m b/herbert_core/utilities/classes/@serializable/private/eq_.m deleted file mode 100644 index 4ec47ea1b2..0000000000 --- a/herbert_core/utilities/classes/@serializable/private/eq_.m +++ /dev/null @@ -1,44 +0,0 @@ -function [iseq, mess] = eq_ (obj1, obj2, narg_out, names, varargin) -% Check equality of two serializable objects - -[iseq, mess, name_a, name_b, namer, argi] = obj1.process_inputs_for_eq (obj2, ... - narg_out, names, varargin{:}); -if ~iseq - return -end - -iseq = false(numel(obj1),1); -for i=1:numel(obj1) - if nargout == 2 - name_1 = namer(name_a,i); - name_2 = namer(name_b,i); - [iseq(i), mess{i}] = eq_single (obj1(i), obj2(i), ... - 'name_a', name_1, 'name_b', name_2, argi{:}); - else - iseq(i) = eq_single(obj1(i),obj2(i), ... - 'name_a', name_a, 'name_b', name_b, argi{:}); - end -end - -if narg_out > 1 - if any(~iseq) - mess = strjoin(mess,'; '); - else - mess = ''; - end -end - -end - - -%------------------------------------------------------------------------------- -function [iseq, mess] = eq_single (obj1, obj2, ... - name_a, name_a_val, name_b, name_b_val, varargin) -% Compare single pair of serializeble objects - -struc1 = obj1.to_bare_struct(); -struc2 = obj2.to_bare_struct(); -[iseq,mess] = equal_to_tol (struc1, struc2, ... - name_a, name_a_val, name_b, name_b_val, varargin{:}); - -end