Fix v.plt

Fix v.plt

:- begin_tests(v).
:- use_module(u(v)).
:- use_module(u(internal/objects_i)).
:- use_module(u(http/v/http_user_v)).
:- use_module(u(util/lambda)).

test(class_create1, [setup(reload_classes)]) :-
   % test class_create/3 version
   class_create(class_create_test_v, citizen_v, [a, c, b]),
   obj_construct(class_create_test_v, [birthday], [1976], CCTO),
   class_fields(citizen_v, CF), sort(CF, CFS),
   class_fields(class_create_test_v, CCTF), sort(CCTF, CCTFS),
   class_fields_new(class_create_test_v, CCTFN),
   assertion(CF == CFS),
   assertion(CCTF = CCTFS),
   assertion(CCTFN == [a, b, c]),

   ord_subtract(CCTF, CF, New_Fields),
   assertion(New_Fields == CCTFN),

   obj_field(CCTO, age, Age),
   integer(Age),

   obj_key(CCTO, Key),
   assertion(Key == [id]).

test(class_create2, [setup(reload_classes)]) :-
   % test class_create/4 version

   class_create(class_create_test_v, citizen_v, [a, c, b],
                [birthday, a]),
   obj_construct(class_create_test_v, [birthday], [1976], CCTO),
   class_fields(citizen_v, CF), sort(CF, CFS),
   class_fields(class_create_test_v, CCTF), sort(CCTF, CCTFS),
   class_fields_new(class_create_test_v, CCTFN),
   assertion(CF == CFS),
   assertion(CCTF = CCTFS),
   assertion(CCTFN == [a, b, c]),

   ord_subtract(CCTF, CF, New_Fields),
   assertion(New_Fields == CCTFN),

   obj_field(CCTO, age, Age),
   integer(Age),

   obj_key(CCTO, Key),
   assertion(Key == [a, birthday]).

test(class_create3,
     [error(class_exists(class_create_test_v)),
      setup(reload_classes)]
     ) :-
   class_create(class_create_test_v, citizen_v, [a, c, b],
                [birthday, a]),
   class_create(class_create_test_v, citizen_v, [d, e]).

test(class_create_feature1, [setup(reload_classes)]) :-
   class_create(class_create_test_v, citizen_v, [a, c, b], []),
   obj_construct(class_create_test_v, [birthday], [1976], CCTO),
   obj_key(CCTO, Key),
   assertion(Key == []).

test(class_create_key_inheritance,
     [setup(reload_classes)]) :-

   class_create(c1_v, citizen_v, [c1_fld], [id]),
   obj_construct(c1_v, [], [], O),
   arg(1, O, Clid),
   get_keymaster(Clid, Kid),
   class_primary_id(citizen_v, Id),
   assertion(Kid == Id).

% test(class_descendant1,
%      [List == [callup_v, citizen_v, class_create_test_v]]
%     ) :-

%   findall(X, class_descendant(man_v, X), List0),
%   msort(List0, List).

% test(class_descendant2, [List == []]) :-

%   findall(X, class_descendant(callup_v, X), List).

% test(class_descendant3, [List == []]) :-

%   obj_construct(tarjan_vertex_v, [], [], V),
%   obj_rebase((object_v -> callup_v), V, _),
%   findall(X, class_descendant(callup_v, X), List).

test(obj_reinterpret1, L == [man_v]) :-
  obj_construct(man_v, [], [], M),
  findall(C, obj_reinterpret(M, C, _), L1),
  sort(L1, L).

test(obj_reinterpret2, L == [man_v, passport_v]) :-
  obj_construct(man_v, [name, surname, sex], ['Sergei', 'Lodyagin', max], M),
  findall(C, obj_reinterpret(M, C, _), L1),
  sort(L1, L).

test(class_name1) :-

   class_name(man_v).

test(class_name2, [fail]) :-

   class_name(man_man_v).

test(class_name3) :-

   findall(Class, class_name(Class), Names),
   sort(Names, Names2),
   length(Names, N1),
   length(Names2, N2),
   assertion(N1 =:= N2),
   assertion(N1 > 10).

% test(class_same_or_descendant1,
%      [List == [callup_v, citizen_v, class_create_test_v, man_v]]
%     ) :-

%   findall(X, class_same_or_descendant(man_v, X), List0),
%   msort(List0, List).

% test(class_same_or_descendant2,
%      [List == [callup_v]]
%     ) :-

%   findall(X, class_same_or_descendant(callup_v, X), List).

% test(class_same_or_descendant3, [List == [callup_v]]) :-

%   obj_construct(tarjan_vertex_v, [], [], V),
%   obj_rebase((object_v -> callup_v), V, _),
%   findall(X, class_same_or_descendant(callup_v, X), List).

test(class_parent1, [Parent == man_v]) :-
   class_parent(citizen_v, Parent).

test(class_parent1_2, [Parent == man_v]) :-
   obj_construct(citizen_v, [], [], Obj1),
   obj_rebase((man_v -> http_result_v), Obj1, _),
   class_parent(citizen_v, Parent).

test(class_parent2,
     [setup(reload_classes),
      L == [callup_v, class_create_test_v]]) :-

   class_create(class_create_test_v, citizen_v, [a, c, b]),
   findall(Desc, class_parent(Desc, citizen_v), LU),
   msort(LU, L).

test(class_parent2_2, [setup(reload_classes), L == [callup_v]]) :-
   obj_construct(callup_v, [], [], O1),
   obj_parents(O1, [callup_v, http_result_v, citizen_v, man_v,
                    object_v, object_base_v], _),
   findall(Desc, class_parent(Desc, citizen_v), LU),
   msort(LU, L).

test(class_parent3) :-
   findall(p(A, B), class_parent(A, B), L),
   length(L, N),
   assertion(N > 10).

test(class_parent3_2) :-
   obj_construct(callup_v, [], [], O1),
   obj_parents(O1, [callup_v, http_result_v, citizen_v, man_v,
                    object_v, object_base_v], _),
   findall(p(A, B), class_parent(A, B), L),
   assertion(\+ memberchk(p(callup_v, http_result_v), L)).

test(eval_obj_expr1,
     [[E0, E1, E2, E3]
     =@= [Man, HTTP_Result, WWW_Addr, Url]]
     ) :-

   Url = 'http://kogorta.dp.ua',
   obj_construct(www_address_v,
                 [http_request_url], [Url], WWW_Addr),
   obj_construct(http_result_v,
                 [www_address], [WWW_Addr], HTTP_Result),
   obj_construct(man_v,
                 [name], [HTTP_Result], Man),
   eval_obj_expr(Man, E0),
   eval_obj_expr(Man/name, E1),
   eval_obj_expr(Man/name/www_address, E2),
   eval_obj_expr(Man/name/www_address/http_request_url,
                 E3).

test(eval_obj_expr2_list) :-

   Url1 = 'http://kogorta.dp.ua',
   Url2 = 'http://google.com',
   obj_construct(www_address_v,
                 [http_request_url], [Url1], WWW_Addr1),
   obj_construct(www_address_v,
                 [http_request_url], [Url2], WWW_Addr2),
   obj_construct(http_result_v,
                 [www_address], [WWW_Addr1], HTTP_Result1),
   obj_construct(http_result_v,
                 [www_address], [WWW_Addr2], HTTP_Result2),
   [HTTP_Result1, HTTP_Result2] / www_address
   / http_request_url =^= [Url1, Url2].

test(eval_obj_expr3_4_ops) :-

   Url1 = 'http://kogorta.dp.ua',
   Url2 = 'http://google.com',
   obj_construct(www_address_v,
                 [http_request_url], [Url1], WWW_Addr1),
   obj_construct(www_address_v,
                 [http_request_url], [Url2], WWW_Addr2),
   obj_construct(http_result_v,
                 [www_address], [WWW_Addr1], HTTP_Result1),
   obj_construct(http_result_v,
                 [www_address], [WWW_Addr2], HTTP_Result2),
   maplist(\Name^Obj^
          obj_construct(man_v, [name], [Name], Obj),
           [HTTP_Result1, HTTP_Result2],
           Mans),
   Mans / name / www_address / http_request_url
      =^= [Url1, Url2].

test(eval_obj_expr4_compound1,
     [error(no_object_field(_, name), _)]) :-

   obj_construct(man_v, [name], ['Sergei'], M1),
   obj_construct(man_v, [name], ['Artemiy'], M2),
   obj_construct(www_address_v, [http_request_url],
                 ['http://kogorta.dp.ua'], A1),
   (p(M1, A1) = p(M2, _)) / name ^= _.

test(eval_obj_expr4_compound2) :-

   obj_construct(man_v, [name], ['Sergei'], M1),
   obj_construct(man_v, [name], ['Artemiy'], M2),
   obj_construct(www_address_v, [http_request_url],
                 ['http://kogorta.dp.ua'], A1),
   (p(M1, A1) = p(M2, A2)) // name ^= R1,
   R1 // name ^= R2,
   R2 // http_request_url ^= R3,
   assertion(R1 == (p('Sergei', A1) = p('Artemiy', A2))),
   assertion(R2 == R1),
   assertion(R3 == (p('Sergei', 'http://kogorta.dp.ua')
                  = p('Artemiy', A2))).

test(eval_obj_expr5_throw1,
     [error(no_object_field(Man, url), _)]) :-

   obj_construct(man_v, [], [], Man),
   Man / url ^= _.

test(eval_obj_expr5_throw2, [error(invalid_object(Url, _), _)]) :-

   Url = 'http://kogorta.dp.ua',
   Url / url ^= _.

test(eval_obj_expr5_thorw3, [error(invalid_object(Url, _), _)]) :-

   Url = 'http://kogorta.dp.ua',
   Url / url / url ^= _.

test(eval_obj_expr5_fail1, [fail]) :-

   obj_construct(man_v, [], [], Man),
   eval_obj_expr(Man / url, fail, _).

test(eval_obj_expr5_fail2, [fail]) :-

   Url = 'http://kogorta.dp.ua',
   eval_obj_expr(Url / url, fail, _).

test(eval_obj_expr5_fail3, [fail]) :-

   Url = 'http://kogorta.dp.ua',
   eval_obj_expr(Url / url / url, fail, _).

test(eval_obj_expr5_weak1, [Man =@= Val]) :-

   obj_construct(man_v, [], [], Man),
   Man // url ^= Val.

test(eval_obj_expr5_weak2, [Url == Val]) :-

   Url = 'http://kogorta.dp.ua',
   Url // url ^= Val.

test(eval_obj_expr5_weak3, [Url == Val]) :-

   Url = 'http://kogorta.dp.ua',
   Url // url // url ^= Val.

test(eval_obj_expr6_list) :-

   obj_construct(http_header_v, [body], [body], H1),
   obj_construct(http_header_v, [], [], H2),
   H2/name ^= [a, H1/body],
   assertion(H2/name =^= [a, body]).

test(eval_obj_expr6_compound) :-

   obj_construct(http_header_v, [body], [body], H1),
   obj_construct(http_header_v, [], [], MH),
   MH/name ^= p(a, H1/body) // ss,
   assertion(MH/name =^= p(a, body)).

test(eval_obj_expr7) :-

   V = [s, l],
   obj_construct(man_v, [name, surname], V, Obj),
   assertion(Obj / [name, surname] =^= V).

test(eval_obj_expr8) :-

   obj_construct(http_header_v, [name, body], [connection, x], H1),
   obj_construct(http_header_v, [name, body], [date, y], H2),
   obj_construct(http_general_headers_v, [connection, date], [H1, H2], O),
   assertion(O / [date, connection] / body =^= [y, x]).

test(eval_obj_expr9) :-
   Url = 'http://kogorta.dp.ua',
   Name = 'Oleg',
   obj_construct(www_address_v, [http_request_url], [Url], WWW_Addr),
   obj_construct(man_v,
                 [name, surname],
                 [Name, WWW_Addr], O),
   assertion(O / [name, surname / http_request_url]
            =^= [Name, Url]).

test(eval_obj_expr10, [Value =@= _]) :-
   obj_construct(man_v, [], [], Obj),
   eval_obj_expr(Obj / name // no_such_field123, Value ).

test(eval_obj_expr11_1, [fail]) :-
   obj_construct(man_v, [], [], Obj),
   eval_obj_expr(Obj / no_such_field123, fail, _).

test(eval_obj_expr11_2, [fail]) :-
   eval_obj_expr(_ / fld, fail, _).

test(obj_construct_with_evals1) :-

    obj_construct(citizen_v,
                  [functor, class, birthday],
                  [citizen_v, citizen_v, 1994], O1),
    obj_field(O1, class, Class1),
    assertion(Class1 == citizen_v),

    obj_construct(citizen_v,
                  [birthday, functor, class],
                  [1994, citizen_v, citizen_v], O2),
    obj_field(O2, class, Class2),
    assertion(Class2 == citizen_v),

    obj_construct(citizen_v,
                  [birthday, sex, functor, class],
                  [1994, man, citizen_v, callup_v], O3),
    obj_field(O3, class, Class3),
    assertion(Class3 == callup_v),

    obj_construct(citizen_v,
                  [functor, class, birthday, sex],
                  [citizen_v, callup_v, 1994, man], O4),
    obj_field(O4, class, Class4),
    assertion(Class4 == callup_v),

    obj_construct(citizen_v,
                  [functor, class, birthday, sex],
                  [X, Y, 1994, man], O5),
    obj_field(O5, class, Class5),
    assertion(Class5 == callup_v),
    assertion(X = citizen_v),
    assertion(Y = callup_v).

test(obj_construct_bug1) :-

   class_fields(man_v, Field_Names),
   obj_construct(man_v, Field_Names, Field_Names, Obj),
   Obj =.. [man_v, _|Field_Names2],

   assertion(Field_Names == Field_Names2).

test(obj_copy1) :-

   obj_construct(man_v, [], [], M1),
   obj_copy(M1, M2),
   obj_field(M1, name, 'Masha'),
   obj_field(M2, name, 'Vitya').

test(obj_copy2) :-

   new_http_user(U1),
   obj_copy(U1, U2),
   eval_obj_expr(U1 / www_address / cookies_db, Key1),
   eval_obj_expr(U2 / www_address / cookies_db, Key2),
   assertion(Key1 \= Key2).

test(obj_diff1,
     [Diff == [diff(name, 'Sergei', 'Artemiy')]]) :-

   obj_construct(man_v, [name, surname], ['Sergei', 'Lodyagin'], M1),
   obj_construct(man_v, [name, surname], ['Artemiy', 'Lodyagin'], M2),
   obj_diff(M1, M2, Diff).

test(obj_diff2,
     [Diff == [diff(name, 'Sergei', 'Artemiy')]]) :-

   obj_construct(man_v, [name, surname], ['Sergei', 'Lodyagin'], M1_0),
   obj_rebase((object_v -> db_object_v), M1_0, M1),
   obj_construct(man_v, [name, surname], ['Artemiy', 'Lodyagin'], M2),
   obj_diff(M1, M2, Diff).

% After some time it will always fails (because it depends
% on the current year).
test(obj_downcast1,
     [C1 =@= callup_v(Class_Id, 1994, _, _, _, _, _, man, _, _)]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], C0),
   obj_downcast(C0, C1),
   arg(1, C1, Class_Id).

% Downcast of rebased object
test(obj_downcast_rebased,
     [% birthday, country, db_key, db_ref, fit_..., height, id, name, sex, surname, weight
      true(C2 =@= callup_v(C2_Class_Id, 1294, _, _, _, _, _, _, _, man, _, _))
     ]) :-
   obj_construct(citizen_v, [sex, birthday], [man, 1994], C0),
   obj_rebase((object_v -> db_object_v), C0, C1),
   obj_downcast(C1, callup_v, C2),
   obj_construct(callup_v, [], [], CC),
   arg(1, C2, C2_Class_Id),
   arg(1, CC, CC_Class_Id),
   assertion(C2_Class_Id =\= CC_Class_Id).

test(obj_field1, [Flds == Vals]) :-

   class_fields(citizen_v, Flds),
   obj_construct(citizen_v, Flds, Flds, Obj),
   findall(Val, (obj_field(Obj, Fld, Val), member(Fld, Flds)), Vals).

test(obj_field2, [Flds3 == Flds4]) :-
% Each eval field must be evaluable only once

   class_fields(citizen_v, Flds),
   obj_construct(citizen_v, Flds, Flds, Obj),
   findall(Fld, obj_field(Obj, Fld, _), Flds2),
   sort(Flds2, Flds3),
   msort(Flds2, Flds4).

test(obj_field3, [Surname == 'Grisha']) :-

   obj_construct(man_v, [], [], Man),
   obj_field(Man, name, Name),
   obj_field(Man, surname, Name),
   Name = 'Grisha',
   obj_field(Man, surname, Surname).

test(obj_field_bug1, [fail]) :-

   obj_construct(citizen_v, [sex], [woman], Obj),
   obj_field(Obj, sex, man).

test(obj_is_descendant1, [List == [object_base_v, object_v]]) :-

   obj_construct(man_v, [], [], Man),
   findall(X, obj_is_descendant(Man, X), List0),
   msort(List0, List).

test(obj_is_descendant2) :-

   obj_construct(man_v, [], [], Man),
   \+ obj_is_descendant(Man, db_object_v),
   obj_rebase((object_v -> db_object_v), Man, Man2),
   obj_is_descendant(Man2, db_object_v).

test(obj_is_descendant3) :-
	obj_construct(citizen_v, [], [], C),
	obj_construct(object_v, [], [], M),
	obj_is_descendant(C, M).

test(obj_same_or_descendant1, [List == [ man_v, object_base_v, object_v]]) :-
   obj_construct(man_v, [], [], Man),
   findall(X, obj_same_or_descendant(Man, X), List0),
   msort(List0, List).

test(obj_same_or_descendant2) :-
   obj_construct(man_v, [], [], Man),
   \+ obj_same_or_descendant(Man, db_object_v),
   obj_rebase((object_v -> db_object_v), Man, Man2),
   obj_same_or_descendant(Man2, db_object_v).

test(obj_same_or_descendant3) :-
	obj_construct(citizen_v, [], [], C),
	obj_same_or_descendant(C, citizen_v).

test(obj_set_field1, [Surname =@= _]) :-

   obj_construct(man_v, [], [], Man),
   obj_set_field(Man, name, Name),
   obj_set_field(Man, surname, Name),
   Name = 'Grisha',
   obj_field(Man, surname, Surname).

test(obj_set_field2, [Surname =@= 'Grisha']) :-

   obj_construct(man_v, [name, surname], [Name, Name], Man),
   obj_set_field(Man, name, 'Grisha'),
   obj_field(Man, surname, Surname).

test(obj_key1) :-

   obj_construct(man_v, [sex, name], [man, 'Adam'], Man1),
   obj_key(Man1, Key1),
   assertion(Key1 == [name, surname]),
   obj_key_value(Man1, Key_Value1),
   assertion(Key_Value1 =@= ['Adam', _]),

   obj_construct(citizen_v,
                 [sex, surname, country],
                 [man, 'Mayakovsky', ['Soviet Union']],
                 Man2),
   obj_key(Man2, Key2),
   assertion(Key2 == [id]),
   obj_key_value(Man2, Key_Value2),
   assertion(Key_Value2 =@= [_]).

test(obj_key2) :-

   obj_construct(man_v, [sex, name], [man, 'Adam'], Man1_0),
   obj_rebase((object_v -> db_object_v), Man1_0, Man1),
   obj_key(Man1, Key1),
   assertion(Key1 == [name, surname]),
   obj_key_value(Man1, Key_Value1),
   assertion(Key_Value1 =@= ['Adam', _]),

   obj_construct(citizen_v,
                 [sex, surname, country],
                 [man, 'Mayakovsky', ['Soviet Union']],
                 Man2_0),
   obj_rebase((object_v -> db_object_v), Man2_0, Man2),
   obj_key(Man2, Key2),
   assertion(Key2 == [id]),
   obj_key_value(Man2, Key_Value2),
   assertion(Key_Value2 =@= [_]).

test(obj_list1,
     [List =@= [country = ['Soviet Union'],
                sex = man,
                surname = 'Mayakovsky']]
     ) :-

   obj_construct(citizen_v,
                 [sex, surname, country],
                 [man, 'Mayakovsky', ['Soviet Union']],
                 Man),
   obj_list(Man, List).

test(obj_list2, [List =@= []]) :-

   obj_construct(citizen_v, [], [], Man),
   obj_list(Man, List).

test(obj_parents1_1,
     [P = [citizen_v, man_v, object_v, object_base_v]]) :-

   obj_construct(citizen_v, [], [], V),
   obj_parents(V, P).

test(obj_parents2_1) :-

   obj_construct(citizen_v,
                 [sex, surname, country, birthday],
                 [man, 'Mayakovsky', ['Soviet Union'], 1994],
                 Man1),
   New_Parents_Order = [man_v, citizen_v, object_v, object_base_v],
   obj_parents(Man1, New_Parents_Order, Man2),
   obj_parents(Man1, P1),
   assertion(P1 == [citizen_v, man_v, object_v, object_base_v]),
   obj_parents(Man2, P2),
   assertion(P2 == New_Parents_Order),
   obj_list(Man1, L1),
   obj_list(Man2, L2),
   assertion(L1 == L2),
   obj_field(Man1, class, C1),
   obj_field(Man2, class, C2),
   obj_field(Man1, functor, F1),
   obj_field(Man2, functor, F2),
   assertion([F1, F2, C1, C2] == [citizen_v, man_v, callup_v, callup_v]).

test(obj_parents2_bug1) :-

   obj_construct(man_v, [name, surname], [s, l], M),
   obj_parents(M, [man_v, db_object_v, object_v, object_base_v], M1),
   obj_unify(M1, [name, surname], NS),
   assertion(NS == [s, l]).

test(obj_rebase1) :-

   obj_construct(http_request_headers_v, [], [], V1),
   obj_parents(V1, P1),
   assertion(P1 == [http_request_headers_v, http_headers_v,
                    object_v,object_base_v]),
   obj_rebase((http_headers_v -> http_response_headers_v),
              V1, V2),
   obj_parents(V2, P2),
   assertion(P2 == [http_request_headers_v,
                    http_response_headers_v,http_headers_v,
                    object_v,object_base_v]),
   obj_rebase((http_request_headers_v ->
               http_invalid_mixed_headers_v), V2, V3),
   obj_parents(V3, P3),
   assertion(P3 == [http_invalid_mixed_headers_v,
                    http_invalid_headers_v,
                    http_headers_v,
                    object_v,object_base_v]).

test(obj_rebase2_transitivity,
     [blocked(rebase_family)]
     ) :-

   obj_construct(citizen_v, [], [], M1),
   obj_rebase((object_v -> db_object_v), M1, M2),
   obj_rebase((man_v -> tarjan_vertex_v), M2, M3),
   obj_parents(M3, P3),
   assertion(P3 == [citizen_v, tarjan_vertex_v, db_object_v,
                    object_v, object_base_v]).

test(obj_rebase3_transitivity2,
     [blocked(rebase_family)]
     ) :-

   obj_construct(citizen_v, [], [], M1),
   obj_rebase((object_v -> db_object_v), M1, M2),
   obj_rebase((man_v -> tarjan_vertex_v), M2, M3),
   foreach(obj_field(M3, _, _), true).

test(obj_rebase4) :-
   obj_construct(http_header_v, [], [], H1),
   obj_rebase((http_header_v -> http_invalid_header_v), H1, H2),
   obj_parents(H2, P2),
   assertion(P2 == [http_invalid_header_v, http_header_v, object_v,
                    object_base_v]).

test(obj_rebase_keymaster) :-
   obj_construct(citizen_v, [], [], Citizen0),
   obj_construct(callup_v, [], [], Callup0),
   obj_rebase((object_v -> db_object_v), Citizen0, Citizen),
   obj_rebase((object_v -> db_object_v), Callup0, Callup),
   arg(1, Citizen, CiId),
   arg(1, Callup, CaId),
   get_keymaster(CiId, K1_Id),
   get_keymaster(CaId, K2_Id),
   assertion(K1_Id == K2_Id).

test(obj_rebase_bug1) :-
   obj_construct(man_v, [sex, name], [man, 'Adam'], Obj1_0),
   obj_rebase((object_v -> db_object_v), Obj1_0, Obj1),

   obj_construct(man_v, [sex, name], [man, 'Adam'], Obj2_0),
   obj_rebase((object_v -> db_object_v), Obj2_0, Obj2),

   arg(1, Obj1, Class_Id1),
   arg(1, Obj2, Class_Id2),

   assertion(Class_Id1 =:= Class_Id2),

   obj_rebase((db_object_v -> object_v), Obj2, Obj3),

   arg(1, Obj2_0, Class_Id0),
   arg(1, Obj3, Class_Id3),
   assertion(Class_Id0 =:= Class_Id3),
   assertion(Obj2_0 == Obj3).

test(obj_rebase_bug2) :-

   obj_construct(citizen_v, [sex], [man], Obj1_0),
   obj_rebase((object_v -> db_object_v), Obj1_0, Obj1),

   obj_construct(citizen_v, [sex], [man], Obj2_0),
   obj_rebase((object_v -> db_object_v), Obj2_0, Obj2),

   arg(1, Obj1, Class_Id1),
   arg(1, Obj2, Class_Id2),

   assertion(Class_Id1 =:= Class_Id2),

   obj_rebase((db_object_v -> object_v), Obj2, Obj3),

   arg(1, Obj2_0, Class_Id0),
   arg(1, Obj3, Class_Id3),
   assertion(Class_Id0 =:= Class_Id3),
   assertion(Obj2_0 == Obj3).

test(obj_rebase_bug3_1) :-

   obj_construct(db_object_v, [], [], Obj1_0),
   obj_rebase((object_v -> db_object_v), Obj1_0, Obj1),

   obj_construct(db_object_v, [], [], Obj2_0),
   obj_rebase((object_v -> db_object_v), Obj2_0, Obj2),

   arg(1, Obj1, Class_Id1),
   arg(1, Obj2, Class_Id2),

   assertion(Class_Id1 =:= Class_Id2),

   obj_rebase((db_object_v -> object_v), Obj2, Obj3),

   arg(1, Obj2_0, Class_Id0),
   arg(1, Obj3, Class_Id3),
   assertion(Class_Id0 =\= Class_Id3),

   class_primary_id(object_v, Object_V_Id),
   assertion(Obj3 == object_v(Object_V_Id)).

test(obj_rebase_bug3_2) :-

   obj_construct(citizen_v, [], [], Obj1_0),
   obj_rebase((man_v -> citizen_v), Obj1_0, Obj1),

   obj_construct(citizen_v, [], [], Obj2_0),
   obj_rebase((object_v -> man_v), Obj2_0, Obj2),

   arg(1, Obj1, Class_Id1),
   arg(1, Obj2, Class_Id2),

   assertion(Class_Id1 =:= Class_Id2).

test(obj_rebase_bug4,
     [throws(error(cant_rebase_to_object_base_v,
                   context(obj_rebase/3, _)))]) :-

   obj_construct(citizen_v, [], [], Obj1_0),
   obj_rebase((citizen_v -> object_base_v), Obj1_0, Obj1),

   obj_construct(citizen_v, [], [], Obj2_0),
   obj_rebase((citizen_v -> object_base_v), Obj2_0, Obj2),

   arg(1, Obj1, Class_Id1),
   arg(1, Obj2, Class_Id2),

   assertion(Class_Id1 =:= Class_Id2),

   obj_rebase((object_base_v -> citizen_v), Obj2, Obj3),

   arg(1, Obj2_0, Class_Id0),
   arg(1, Obj3, Class_Id3),
   assertion(Class_Id0 =:= Class_Id3),
   assertion(Obj2_0 == Obj3).

test(obj_rebase_bug5, [X == 1]) :-

   obj_construct(http_headers_v, [], [], O0),
   obj_rebase((http_headers_v
              -> http_response_headers_v), O0, O1),
   obj_rebase((http_headers_v
              -> http_invalid_bulk_headers_v), O1, O2),
   obj_rebase((http_headers_v
              -> http_response_with_cookies_headers_v),
              O2, O3),
   O3 / set_cookie ^= 1,
   obj_rebase((http_headers_v
              -> http_response_with_cookies_headers_v),
              O3, O4),
   obj_field(O4, set_cookie, X).

test(obj_reset_fields1) :-

   obj_construct(man_v,
                 [sex, name, weight, height],
                 [man, 'Simeon', 63, 1.75], Man0),

   obj_reset_fields([name, height], Man0, Man1),
   obj_class_id(Man1, Class_Id),
   assertion(Man1 =@= man_v(Class_Id, _, _, man, _, 63)),

   obj_reset_fields([weight], Man1, Man2),
   assertion(Man2 =@= man_v(Class_Id, _, _, man, _, _)),

   obj_reset_fields([], Man2, Man3),
   assertion(Man3 =@= Man2).

test(obj_reset_fields2, [fail]) :-

   obj_construct(man_v,
                 [sex, name, weight, height],
                 [man, 'Simeon', 63, 1.75], Man0),

   obj_reset_fields([name, height, age], Man0, _).

test(obj_reset_fields_weak) :-

   obj_construct(man_v,
                 [sex, name, weight, height],
                 [man, 'Simeon', 63, 1.75], Man0),

   obj_reset_fields_weak([name, height, age], Man0, Man1),
   obj_class_id(Man1, Class_Id),
   assertion(Man1 =@= man_v(Class_Id, _, _, man, _, 63)).

test(obj_reset_fields_with_evals, [fail]) :-

   obj_construct(citizen_v, [sex], [man], O),
   obj_reset_fields([age], O, _).

test(obj_rewrite) :-

   obj_construct(man_v,
                 [name, height, weight],
                 ['Luda', 1.40, 99], Luda1),
   obj_rewrite(Luda1,
               [height, weight, name],
               [Old_Height, Old_Weight, Name],
               [1.44, 69, Name],
               Luda2),
   assertion([Old_Height, Old_Weight] =@= [1.40, 99]),
   obj_rewrite(Luda2,
               [height, weight, name],
               Luda2_Pars,
               [1.45, 64, _],
               Luda3),
   assertion(Luda2_Pars =@= [1.44, 69, 'Luda']),
   named_args_unify(Luda3, [height, weight, name], Luda3_Pars),
   assertion(Luda3_Pars =@= [1.45, 64, _]).

test(obj_rewrite_weak1,
     [throws(error(no_object_field(Luda1, country), _))]) :-

   obj_construct(man_v,
                 [name, height, weight],
                 ['Luda', 1.40, 99], Luda1),
   obj_rewrite(Luda1,
               [height, weight, name, country],
               _,
               [1.44, 69, _, 'UK'],
               _).

test(obj_rewrite_weak2,
     [[Old_Height, Old_Weight, Name, Old_Country]
     =@= [1.40, 99, 'Luda', _]]
     ) :-

   obj_construct(man_v,
                 [name, height, weight],
                 ['Luda', 1.40, 99], Luda1),
   obj_rewrite(Luda1, weak,
               [height, weight, name, country],
               [Old_Height, Old_Weight, Name, Old_Country],
               [1.44, 69, Name, 'UK'],
               _).

test(obj_rewrite_weak3, [fail]) :-

   obj_construct(man_v,
                 [name, height, weight],
                 ['Luda', 1.40, 99], Luda1),
   obj_rewrite(Luda1, fail,
               [height, weight, name, country],
               _,
               [1.44, 69, _, 'UK'],
               _).

test(obj_rewrite_with_evals1, [X == callup_v]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], O),
   obj_rewrite(O, [class], [X], [callup_v], _).

test(obj_rewrite_with_evals2, [fail]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], O),
   obj_rewrite(O, [class], [_], [citizen_v], _).

test(obj_rewrite_with_evals3, [X == callup_v]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], O),
   obj_rewrite(O, [class], [X], [X], _).

test(obj_rewrite_with_evals4) :-
% <NB> can't reset eval field, compare with test(obj_rewrite)

   obj_construct(citizen_v, [sex, birthday], [man, 1994], O),
   obj_rewrite(O, [class], [_], [_], _).

test(obj_sort_parents1,
     [P4 == [http_invalid_mixed_headers_v,
             http_invalid_headers_v,
             http_request_headers_v,
             http_response_headers_v,
             http_headers_v,
             object_v, object_base_v]]
     ) :-

   obj_construct(http_request_headers_v, [], [], V1),
   obj_rebase((http_headers_v -> http_response_headers_v),
              V1, V2),
   obj_rebase((http_headers_v -> http_invalid_mixed_headers_v),
              V2, V3),

   obj_sort_parents(V3, [http_invalid_bulk_headers_v,
                         http_invalid_mixed_headers_v,
                         http_invalid_headers_v,
                         http_request_headers_v,
                         http_response_headers_v,
                         http_headers_v,
                         tarjan_vertex_v,
                         db_object_v,
                         object_v, object_base_v], V4),
   obj_parents(V4, P4),
   functor(V4, F4, _),
   assertion(F4 == http_invalid_mixed_headers_v).

test(obj_sort_parents2,
     [throws(error(insufficient_class_order(Order,
                                            Orig_Order), _))]
     ) :-

   Order = [http_invalid_bulk_headers_v,
            http_invalid_mixed_headers_v,
            http_request_headers_v,
            http_response_headers_v,
            http_headers_v,
            tarjan_vertex_v,
            db_object_v,
            object_v, object_base_v],

   obj_construct(http_request_headers_v, [], [], V1),
   obj_rebase((http_headers_v -> http_response_headers_v),
              V1, V2),
   obj_rebase((http_headers_v -> http_invalid_mixed_headers_v),
              V2, V3),

   obj_parents(V3, Orig_Order),
   obj_sort_parents(V3, Order, _).

test(obj_sort_parents_bug1) :-

   new_http_user(HTTP_User),
   obj_rebase((object_v -> citizen_v),
              HTTP_User, U1),

   class_parents(http_user_v, HTTP_User_Parents),
   append([citizen_v, man_v], HTTP_User_Parents,
          Parents_Order),

   obj_sort_parents(U1, Parents_Order, HTTP_Citizen),
   % citizen_v -> man_v -> http_user_v -> ...object_base_v

   obj_copy(HTTP_Citizen, HTTP_Citizen_Copy),
   eval_obj_expr(HTTP_Citizen / www_address / cookies_db, Key1),
   eval_obj_expr(HTTP_Citizen_Copy / www_address / cookies_db, Key2),
   assertion(Key1 \= Key2).

test(class_fields) :-

   class_fields(object_base_v, Object_Base_V_Fields),
   assertion(Object_Base_V_Fields == []),

   class_fields_new(object_base_v, Object_Base_V_New_Fields),
   assertion(Object_Base_V_New_Fields == []),

   class_fields(object_v, Object_V_Fields),
   assertion(Object_V_Fields == []),

   class_fields_new(object_v, Object_V_New_Fields),
   assertion(Object_V_New_Fields == []),

   class_fields(man_v, Man_V_Fields),
   assertion(Man_V_Fields == [height, name, sex, surname, weight]),

   class_fields_new(man_v, Man_V_New_Fields),
   assertion(Man_V_New_Fields == [height, name, sex, surname,
                                  weight]),

   class_fields(citizen_v, Citizen_V_Fields),
   assertion(Citizen_V_Fields == [birthday, country, height, id,
                                  name, sex, surname, weight]),

   class_fields_new(citizen_v, Citizen_V_New_Fields),
   assertion(Citizen_V_New_Fields == [birthday, country, id]).

test(cleanup_obj_rebase, [blocked(transaction_bug), N1 =:= N2]) :-

   aggregate(count, A^B^C^(objects:class_id(A, B, C)), N1),
   catch((obj_construct(numeric_id_v, [], [], Obj1),
          obj_rebase((object_v -> citizen_v), Obj1, _)),
         E, true),
   E = error(EX, _), functor(EX, duplicate_field, _),
   aggregate(count, A^B^C^(objects:class_id(A, B, C)), N2).

% After some time it will always fails (because it depends
% on the current year, see The Uranium Book).
test(eval_fields1, [Class == callup_v]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], C),
   obj_field(C, class, Class).

test(eval_fields2) :-

   % man_v doesn't define class eval, so in this example
   % the eval from citizen_v is always used.

   obj_construct(citizen_v,
                 [sex, birthday], [man, 1994], C1),
   obj_field(C1, class, Cl1),
   obj_parents(C1,
               [man_v, citizen_v, object_v, object_base_v],
               C2),
   obj_field(C2, class, Cl2),
   assertion(Cl1 == callup_v),
   assertion(Cl2 == callup_v).

test(eval_fields3,
     [blocked(need_to_see)]
     ) :-

   obj_construct(callup_v,
                 [sex, birthday], [man, 1994], C1),
   obj_field(C1, class, Cl1),
   obj_rebase((citizen_v -> man_v), C1, C2),
   obj_parents(C2, P2),

   % for sure, citizen_v is not present
   assertion(P2 ==
            [callup_v, man_v, object_v, object_base_v]),

   obj_field(C2, class, Cl2),
   assertion(Cl1 == callup_v),
   assertion(Cl2 == man_v).

test(eval_fields4) :-

   obj_construct(adder_v, [], [], Adder1),

   obj_unify(Adder1, [a, b, c], [3, 11, C]),
   assertion(C == 14),

   obj_unify(Adder1, [z, y, x], [2, 10, X]),
   assertion(X == 12).

test(eval_fields5) :-

   obj_construct(adder_v, [a, b, c], [3, 11, C], _),
   assertion(C == 14),

   obj_construct(adder_v, [z, y, x], [2, 10, X], _),
   assertion(X == 12).

% eval inheritance
test(eval_fields6) :-

   obj_construct(vector_adder_v, [], [], Adder1),

   obj_unify(Adder1,
             [a, b, c],
             [[2, 3], [10, 11], C]),
   assertion(C == [12, 14]),

   obj_unify(Adder1, [z, y, x], [2, 10, X]),
   assertion(X == 12).

test(eval_fields7) :-

   obj_construct(vector_adder_v,
                 [a, b, c],
                 [[2, 3], [10, 11], C],
                 _),
   assertion(C == [12, 14]),

   obj_construct(adder_v, [z, y, x], [2, 10, X], _),
   assertion(X == 12).

reload_classes :-
   current_prolog_flag(verbose, Old_Verbose),
   set_prolog_flag(verbose, silent),
   reload_all_classes,
   set_prolog_flag(verbose, Old_Verbose).

:- end_tests(v).

:- begin_tests(v).
:- use_module(u(v)).
:- use_module(u(internal/objects_i)).
:- use_module(u(http/v/http_user_v)).
:- use_module(u(util/lambda)).

test(class_create1, [setup(reload_classes)]) :-
   % test class_create/3 version
   class_create(class_create_test_v, citizen_v, [a, c, b]),
   obj_construct(class_create_test_v, [birthday], [1976], CCTO),
   class_fields(citizen_v, CF), sort(CF, CFS),
   class_fields(class_create_test_v, CCTF), sort(CCTF, CCTFS),
   class_fields_new(class_create_test_v, CCTFN),
   assertion(CF == CFS),
   assertion(CCTF = CCTFS),
   assertion(CCTFN == [a, b, c]),

   ord_subtract(CCTF, CF, New_Fields),
   assertion(New_Fields == CCTFN),

   obj_field(CCTO, age, Age),
   integer(Age),

   obj_key(CCTO, Key),
   assertion(Key == [id]).

test(class_create2, [setup(reload_classes)]) :-
   % test class_create/4 version

   class_create(class_create_test_v, citizen_v, [a, c, b],
                [birthday, a]),
   obj_construct(class_create_test_v, [birthday], [1976], CCTO),
   class_fields(citizen_v, CF), sort(CF, CFS),
   class_fields(class_create_test_v, CCTF), sort(CCTF, CCTFS),
   class_fields_new(class_create_test_v, CCTFN),
   assertion(CF == CFS),
   assertion(CCTF = CCTFS),
   assertion(CCTFN == [a, b, c]),

   ord_subtract(CCTF, CF, New_Fields),
   assertion(New_Fields == CCTFN),

   obj_field(CCTO, age, Age),
   integer(Age),

   obj_key(CCTO, Key),
   assertion(Key == [a, birthday]).

test(class_create3,
     [error(class_exists(class_create_test_v)),
      setup(reload_classes)]
     ) :-
   class_create(class_create_test_v, citizen_v, [a, c, b],
                [birthday, a]),
   class_create(class_create_test_v, citizen_v, [d, e]).

test(class_create_feature1, [setup(reload_classes)]) :-
   class_create(class_create_test_v, citizen_v, [a, c, b], []),
   obj_construct(class_create_test_v, [birthday], [1976], CCTO),
   obj_key(CCTO, Key),
   assertion(Key == []).

test(class_create_key_inheritance,
     [setup(reload_classes)]) :-

   class_create(c1_v, citizen_v, [c1_fld], [id]),
   obj_construct(c1_v, [], [], O),
   arg(1, O, Clid),
   get_keymaster(Clid, Kid),
   class_primary_id(citizen_v, Id),
   assertion(Kid == Id).

% test(class_descendant1,
%      [List == [callup_v, citizen_v, class_create_test_v]]
%     ) :-

%   findall(X, class_descendant(man_v, X), List0),
%   msort(List0, List).

% test(class_descendant2, [List == []]) :-

%   findall(X, class_descendant(callup_v, X), List).

% test(class_descendant3, [List == []]) :-

%   obj_construct(tarjan_vertex_v, [], [], V),
%   obj_rebase((object_v -> callup_v), V, _),
%   findall(X, class_descendant(callup_v, X), List).

test(obj_reinterpret1, L == [man_v]) :-
  obj_construct(man_v, [], [], M),
  findall(C, obj_reinterpret(M, C, _), L1),
  sort(L1, L).

test(obj_reinterpret2, L == [man_v, passport_v]) :-
  obj_construct(man_v, [name, surname, sex], ['Sergei', 'Lodyagin', max], M),
  findall(C, obj_reinterpret(M, C, _), L1),
  sort(L1, L).

test(class_name1) :-

   class_name(man_v).

test(class_name2, [fail]) :-

   class_name(man_man_v).

test(class_name3) :-

   findall(Class, class_name(Class), Names),
   sort(Names, Names2),
   length(Names, N1),
   length(Names2, N2),
   assertion(N1 =:= N2),
   assertion(N1 > 10).

% test(class_same_or_descendant1,
%      [List == [callup_v, citizen_v, class_create_test_v, man_v]]
%     ) :-

%   findall(X, class_same_or_descendant(man_v, X), List0),
%   msort(List0, List).

% test(class_same_or_descendant2,
%      [List == [callup_v]]
%     ) :-

%   findall(X, class_same_or_descendant(callup_v, X), List).

% test(class_same_or_descendant3, [List == [callup_v]]) :-

%   obj_construct(tarjan_vertex_v, [], [], V),
%   obj_rebase((object_v -> callup_v), V, _),
%   findall(X, class_same_or_descendant(callup_v, X), List).

test(class_parent1, [Parent == man_v]) :-
   class_parent(citizen_v, Parent).

test(class_parent1_2, [Parent == man_v]) :-
   obj_construct(citizen_v, [], [], Obj1),
   obj_rebase((man_v -> http_result_v), Obj1, _),
   class_parent(citizen_v, Parent).

test(class_parent2,
     [setup(reload_classes),
      L == [callup_v, class_create_test_v]]) :-

   class_create(class_create_test_v, citizen_v, [a, c, b]),
   findall(Desc, class_parent(Desc, citizen_v), LU),
   msort(LU, L).

test(class_parent2_2, [setup(reload_classes), L == [callup_v]]) :-
   obj_construct(callup_v, [], [], O1),
   obj_parents(O1, [callup_v, http_result_v, citizen_v, man_v,
                    object_v, object_base_v], _),
   findall(Desc, class_parent(Desc, citizen_v), LU),
   msort(LU, L).

test(class_parent3) :-
   findall(p(A, B), class_parent(A, B), L),
   length(L, N),
   assertion(N > 10).

test(class_parent3_2) :-
   obj_construct(callup_v, [], [], O1),
   obj_parents(O1, [callup_v, http_result_v, citizen_v, man_v,
                    object_v, object_base_v], _),
   findall(p(A, B), class_parent(A, B), L),
   assertion(\+ memberchk(p(callup_v, http_result_v), L)).

test(eval_obj_expr1,
     [[E0, E1, E2, E3]
     =@= [Man, HTTP_Result, WWW_Addr, Url]]
     ) :-

   Url = 'http://kogorta.dp.ua',
   obj_construct(www_address_v,
                 [http_request_url], [Url], WWW_Addr),
   obj_construct(http_result_v,
                 [www_address], [WWW_Addr], HTTP_Result),
   obj_construct(man_v,
                 [name], [HTTP_Result], Man),
   eval_obj_expr(Man, E0),
   eval_obj_expr(Man/name, E1),
   eval_obj_expr(Man/name/www_address, E2),
   eval_obj_expr(Man/name/www_address/http_request_url,
                 E3).

test(eval_obj_expr2_list) :-

   Url1 = 'http://kogorta.dp.ua',
   Url2 = 'http://google.com',
   obj_construct(www_address_v,
                 [http_request_url], [Url1], WWW_Addr1),
   obj_construct(www_address_v,
                 [http_request_url], [Url2], WWW_Addr2),
   obj_construct(http_result_v,
                 [www_address], [WWW_Addr1], HTTP_Result1),
   obj_construct(http_result_v,
                 [www_address], [WWW_Addr2], HTTP_Result2),
   [HTTP_Result1, HTTP_Result2] / www_address
   / http_request_url =^= [Url1, Url2].

test(eval_obj_expr3_4_ops) :-

   Url1 = 'http://kogorta.dp.ua',
   Url2 = 'http://google.com',
   obj_construct(www_address_v,
                 [http_request_url], [Url1], WWW_Addr1),
   obj_construct(www_address_v,
                 [http_request_url], [Url2], WWW_Addr2),
   obj_construct(http_result_v,
                 [www_address], [WWW_Addr1], HTTP_Result1),
   obj_construct(http_result_v,
                 [www_address], [WWW_Addr2], HTTP_Result2),
   maplist(\Name^Obj^
          obj_construct(man_v, [name], [Name], Obj),
           [HTTP_Result1, HTTP_Result2],
           Mans),
   Mans / name / www_address / http_request_url
      =^= [Url1, Url2].

test(eval_obj_expr4_compound1,
     [error(no_object_field(_, name), _)]) :-

   obj_construct(man_v, [name], ['Sergei'], M1),
   obj_construct(man_v, [name], ['Artemiy'], M2),
   obj_construct(www_address_v, [http_request_url],
                 ['http://kogorta.dp.ua'], A1),
   (p(M1, A1) = p(M2, _)) / name ^= _.

test(eval_obj_expr4_compound2) :-

   obj_construct(man_v, [name], ['Sergei'], M1),
   obj_construct(man_v, [name], ['Artemiy'], M2),
   obj_construct(www_address_v, [http_request_url],
                 ['http://kogorta.dp.ua'], A1),
   (p(M1, A1) = p(M2, A2)) // name ^= R1,
   R1 // name ^= R2,
   R2 // http_request_url ^= R3,
   assertion(R1 == (p('Sergei', A1) = p('Artemiy', A2))),
   assertion(R2 == R1),
   assertion(R3 == (p('Sergei', 'http://kogorta.dp.ua')
                  = p('Artemiy', A2))).

test(eval_obj_expr5_throw1,
     [error(no_object_field(Man, url), _)]) :-

   obj_construct(man_v, [], [], Man),
   Man / url ^= _.

test(eval_obj_expr5_throw2, [error(invalid_object(Url, _), _)]) :-

   Url = 'http://kogorta.dp.ua',
   Url / url ^= _.

test(eval_obj_expr5_thorw3, [error(invalid_object(Url, _), _)]) :-

   Url = 'http://kogorta.dp.ua',
   Url / url / url ^= _.

test(eval_obj_expr5_fail1, [fail]) :-

   obj_construct(man_v, [], [], Man),
   eval_obj_expr(Man / url, fail, _).

test(eval_obj_expr5_fail2, [fail]) :-

   Url = 'http://kogorta.dp.ua',
   eval_obj_expr(Url / url, fail, _).

test(eval_obj_expr5_fail3, [fail]) :-

   Url = 'http://kogorta.dp.ua',
   eval_obj_expr(Url / url / url, fail, _).

test(eval_obj_expr5_weak1, [Man =@= Val]) :-

   obj_construct(man_v, [], [], Man),
   Man // url ^= Val.

test(eval_obj_expr5_weak2, [Url == Val]) :-

   Url = 'http://kogorta.dp.ua',
   Url // url ^= Val.

test(eval_obj_expr5_weak3, [Url == Val]) :-

   Url = 'http://kogorta.dp.ua',
   Url // url // url ^= Val.

test(eval_obj_expr6_list) :-

   obj_construct(http_header_v, [body], [body], H1),
   obj_construct(http_header_v, [], [], H2),
   H2/name ^= [a, H1/body],
   assertion(H2/name =^= [a, body]).

test(eval_obj_expr6_compound) :-

   obj_construct(http_header_v, [body], [body], H1),
   obj_construct(http_header_v, [], [], MH),
   MH/name ^= p(a, H1/body) // ss,
   assertion(MH/name =^= p(a, body)).

test(eval_obj_expr7) :-

   V = [s, l],
   obj_construct(man_v, [name, surname], V, Obj),
   assertion(Obj / [name, surname] =^= V).

test(eval_obj_expr8) :-

   obj_construct(http_header_v, [name, body], [connection, x], H1),
   obj_construct(http_header_v, [name, body], [date, y], H2),
   obj_construct(http_general_headers_v, [connection, date], [H1, H2], O),
   assertion(O / [date, connection] / body =^= [y, x]).

test(eval_obj_expr9) :-
   Url = 'http://kogorta.dp.ua',
   Name = 'Oleg',
   obj_construct(www_address_v, [http_request_url], [Url], WWW_Addr),
   obj_construct(man_v,
                 [name, surname],
                 [Name, WWW_Addr], O),
   assertion(O / [name, surname / http_request_url]
            =^= [Name, Url]).

test(eval_obj_expr10, [Value =@= _]) :-
   obj_construct(man_v, [], [], Obj),
   eval_obj_expr(Obj / name // no_such_field123, Value ).

test(eval_obj_expr11_1, [fail]) :-
   obj_construct(man_v, [], [], Obj),
   eval_obj_expr(Obj / no_such_field123, fail, _).

test(eval_obj_expr11_2, [fail]) :-
   eval_obj_expr(_ / fld, fail, _).

test(obj_construct_with_evals1) :-

    obj_construct(citizen_v,
                  [functor, class, birthday],
                  [citizen_v, citizen_v, 1994], O1),
    obj_field(O1, class, Class1),
    assertion(Class1 == citizen_v),

    obj_construct(citizen_v,
                  [birthday, functor, class],
                  [1994, citizen_v, citizen_v], O2),
    obj_field(O2, class, Class2),
    assertion(Class2 == citizen_v),

    obj_construct(citizen_v,
                  [birthday, sex, functor, class],
                  [1994, man, citizen_v, callup_v], O3),
    obj_field(O3, class, Class3),
    assertion(Class3 == callup_v),

    obj_construct(citizen_v,
                  [functor, class, birthday, sex],
                  [citizen_v, callup_v, 1994, man], O4),
    obj_field(O4, class, Class4),
    assertion(Class4 == callup_v),

    obj_construct(citizen_v,
                  [functor, class, birthday, sex],
                  [X, Y, 1994, man], O5),
    obj_field(O5, class, Class5),
    assertion(Class5 == callup_v),
    assertion(X = citizen_v),
    assertion(Y = callup_v).

test(obj_construct_bug1) :-

   class_fields(man_v, Field_Names),
   obj_construct(man_v, Field_Names, Field_Names, Obj),
   Obj =.. [man_v, _|Field_Names2],

   assertion(Field_Names == Field_Names2).

test(obj_copy1) :-

   obj_construct(man_v, [], [], M1),
   obj_copy(M1, M2),
   obj_field(M1, name, 'Masha'),
   obj_field(M2, name, 'Vitya').

test(obj_copy2) :-

   new_http_user(U1),
   obj_copy(U1, U2),
   eval_obj_expr(U1 / www_address / cookies_db, Key1),
   eval_obj_expr(U2 / www_address / cookies_db, Key2),
   assertion(Key1 \= Key2).

test(obj_diff1,
     [Diff == [diff(name, 'Sergei', 'Artemiy')]]) :-

   obj_construct(man_v, [name, surname], ['Sergei', 'Lodyagin'], M1),
   obj_construct(man_v, [name, surname], ['Artemiy', 'Lodyagin'], M2),
   obj_diff(M1, M2, Diff).

test(obj_diff2,
     [Diff == [diff(name, 'Sergei', 'Artemiy')]]) :-

   obj_construct(man_v, [name, surname], ['Sergei', 'Lodyagin'], M1_0),
   obj_rebase((object_v -> db_object_v), M1_0, M1),
   obj_construct(man_v, [name, surname], ['Artemiy', 'Lodyagin'], M2),
   obj_diff(M1, M2, Diff).

% After some time it will always fails (because it depends
% on the current year).
test(obj_downcast1,
     [C1 =@= callup_v(Class_Id, 1994, _, _, _, _, _, man, _, _)]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], C0),
   obj_downcast(C0, C1),
   arg(1, C1, Class_Id).

% Downcast of rebased object
test(obj_downcast_rebased,
     [C2_Class_Id =/= CC_Class_Id,
      % birthday, country, db_key, db_ref, fit_..., height, id, name, sex, surname, weight
      C2 =@= callup_v(C2_Class_Id, 1994, _, _, _, _, _, _, _, man, _, _)]) :-
   obj_construct(citizen_v, [sex, birthday], [man, 1994], C0),
   obj_rebase((object_v -> db_object_v), C0, C1),
   obj_downcast(C1, callup_v, C2),
   obj_construct(callup_v, [], [], CC),
   arg1(1, C2, C2_Class_Id),
   arg1(1, CC, CC_Class_Id).

test(obj_field1, [Flds == Vals]) :-

   class_fields(citizen_v, Flds),
   obj_construct(citizen_v, Flds, Flds, Obj),
   findall(Val, (obj_field(Obj, Fld, Val), member(Fld, Flds)), Vals).

test(obj_field2, [Flds3 == Flds4]) :-
% Each eval field must be evaluable only once

   class_fields(citizen_v, Flds),
   obj_construct(citizen_v, Flds, Flds, Obj),
   findall(Fld, obj_field(Obj, Fld, _), Flds2),
   sort(Flds2, Flds3),
   msort(Flds2, Flds4).

test(obj_field3, [Surname == 'Grisha']) :-

   obj_construct(man_v, [], [], Man),
   obj_field(Man, name, Name),
   obj_field(Man, surname, Name),
   Name = 'Grisha',
   obj_field(Man, surname, Surname).

test(obj_field_bug1, [fail]) :-

   obj_construct(citizen_v, [sex], [woman], Obj),
   obj_field(Obj, sex, man).

test(obj_is_descendant1, [List == [object_base_v, object_v]]) :-

   obj_construct(man_v, [], [], Man),
   findall(X, obj_is_descendant(Man, X), List0),
   msort(List0, List).

test(obj_is_descendant2) :-

   obj_construct(man_v, [], [], Man),
   \+ obj_is_descendant(Man, db_object_v),
   obj_rebase((object_v -> db_object_v), Man, Man2),
   obj_is_descendant(Man2, db_object_v).

test(obj_is_descendant3) :-
	obj_construct(citizen_v, [], [], C),
	obj_construct(object_v, [], [], M),
	obj_is_descendant(C, M).

test(obj_same_or_descendant1, [List == [ man_v, object_base_v, object_v]]) :-
   obj_construct(man_v, [], [], Man),
   findall(X, obj_same_or_descendant(Man, X), List0),
   msort(List0, List).

test(obj_same_or_descendant2) :-
   obj_construct(man_v, [], [], Man),
   \+ obj_same_or_descendant(Man, db_object_v),
   obj_rebase((object_v -> db_object_v), Man, Man2),
   obj_same_or_descendant(Man2, db_object_v).

test(obj_same_or_descendant3) :-
	obj_construct(citizen_v, [], [], C),
	obj_same_or_descendant(C, citizen_v).

test(obj_set_field1, [Surname =@= _]) :-

   obj_construct(man_v, [], [], Man),
   obj_set_field(Man, name, Name),
   obj_set_field(Man, surname, Name),
   Name = 'Grisha',
   obj_field(Man, surname, Surname).

test(obj_set_field2, [Surname =@= 'Grisha']) :-

   obj_construct(man_v, [name, surname], [Name, Name], Man),
   obj_set_field(Man, name, 'Grisha'),
   obj_field(Man, surname, Surname).

test(obj_key1) :-

   obj_construct(man_v, [sex, name], [man, 'Adam'], Man1),
   obj_key(Man1, Key1),
   assertion(Key1 == [name, surname]),
   obj_key_value(Man1, Key_Value1),
   assertion(Key_Value1 =@= ['Adam', _]),

   obj_construct(citizen_v,
                 [sex, surname, country],
                 [man, 'Mayakovsky', ['Soviet Union']],
                 Man2),
   obj_key(Man2, Key2),
   assertion(Key2 == [id]),
   obj_key_value(Man2, Key_Value2),
   assertion(Key_Value2 =@= [_]).

test(obj_key2) :-

   obj_construct(man_v, [sex, name], [man, 'Adam'], Man1_0),
   obj_rebase((object_v -> db_object_v), Man1_0, Man1),
   obj_key(Man1, Key1),
   assertion(Key1 == [name, surname]),
   obj_key_value(Man1, Key_Value1),
   assertion(Key_Value1 =@= ['Adam', _]),

   obj_construct(citizen_v,
                 [sex, surname, country],
                 [man, 'Mayakovsky', ['Soviet Union']],
                 Man2_0),
   obj_rebase((object_v -> db_object_v), Man2_0, Man2),
   obj_key(Man2, Key2),
   assertion(Key2 == [id]),
   obj_key_value(Man2, Key_Value2),
   assertion(Key_Value2 =@= [_]).

test(obj_list1,
     [List =@= [country = ['Soviet Union'],
                sex = man,
                surname = 'Mayakovsky']]
     ) :-

   obj_construct(citizen_v,
                 [sex, surname, country],
                 [man, 'Mayakovsky', ['Soviet Union']],
                 Man),
   obj_list(Man, List).

test(obj_list2, [List =@= []]) :-

   obj_construct(citizen_v, [], [], Man),
   obj_list(Man, List).

test(obj_parents1_1,
     [P = [citizen_v, man_v, object_v, object_base_v]]) :-

   obj_construct(citizen_v, [], [], V),
   obj_parents(V, P).

test(obj_parents2_1) :-

   obj_construct(citizen_v,
                 [sex, surname, country, birthday],
                 [man, 'Mayakovsky', ['Soviet Union'], 1994],
                 Man1),
   New_Parents_Order = [man_v, citizen_v, object_v, object_base_v],
   obj_parents(Man1, New_Parents_Order, Man2),
   obj_parents(Man1, P1),
   assertion(P1 == [citizen_v, man_v, object_v, object_base_v]),
   obj_parents(Man2, P2),
   assertion(P2 == New_Parents_Order),
   obj_list(Man1, L1),
   obj_list(Man2, L2),
   assertion(L1 == L2),
   obj_field(Man1, class, C1),
   obj_field(Man2, class, C2),
   obj_field(Man1, functor, F1),
   obj_field(Man2, functor, F2),
   assertion([F1, F2, C1, C2] == [citizen_v, man_v, callup_v, callup_v]).

test(obj_parents2_bug1) :-

   obj_construct(man_v, [name, surname], [s, l], M),
   obj_parents(M, [man_v, db_object_v, object_v, object_base_v], M1),
   obj_unify(M1, [name, surname], NS),
   assertion(NS == [s, l]).

test(obj_rebase1) :-

   obj_construct(http_request_headers_v, [], [], V1),
   obj_parents(V1, P1),
   assertion(P1 == [http_request_headers_v, http_headers_v,
                    object_v,object_base_v]),
   obj_rebase((http_headers_v -> http_response_headers_v),
              V1, V2),
   obj_parents(V2, P2),
   assertion(P2 == [http_request_headers_v,
                    http_response_headers_v,http_headers_v,
                    object_v,object_base_v]),
   obj_rebase((http_request_headers_v ->
               http_invalid_mixed_headers_v), V2, V3),
   obj_parents(V3, P3),
   assertion(P3 == [http_invalid_mixed_headers_v,
                    http_invalid_headers_v,
                    http_headers_v,
                    object_v,object_base_v]).

test(obj_rebase2_transitivity,
     [blocked(rebase_family)]
     ) :-

   obj_construct(citizen_v, [], [], M1),
   obj_rebase((object_v -> db_object_v), M1, M2),
   obj_rebase((man_v -> tarjan_vertex_v), M2, M3),
   obj_parents(M3, P3),
   assertion(P3 == [citizen_v, tarjan_vertex_v, db_object_v,
                    object_v, object_base_v]).

test(obj_rebase3_transitivity2,
     [blocked(rebase_family)]
     ) :-

   obj_construct(citizen_v, [], [], M1),
   obj_rebase((object_v -> db_object_v), M1, M2),
   obj_rebase((man_v -> tarjan_vertex_v), M2, M3),
   foreach(obj_field(M3, _, _), true).

test(obj_rebase4) :-
   obj_construct(http_header_v, [], [], H1),
   obj_rebase((http_header_v -> http_invalid_header_v), H1, H2),
   obj_parents(H2, P2),
   assertion(P2 == [http_invalid_header_v, http_header_v, object_v,
                    object_base_v]).

test(obj_rebase_keymaster) :-
   obj_construct(citizen_v, [], [], Citizen0),
   obj_construct(callup_v, [], [], Callup0),
   obj_rebase((object_v -> db_object_v), Citizen0, Citizen),
   obj_rebase((object_v -> db_object_v), Callup0, Callup),
   arg(1, Citizen, CiId),
   arg(1, Callup, CaId),
   get_keymaster(CiId, K1_Id),
   get_keymaster(CaId, K2_Id),
   assertion(K1_Id == K2_Id).

test(obj_rebase_bug1) :-
   obj_construct(man_v, [sex, name], [man, 'Adam'], Obj1_0),
   obj_rebase((object_v -> db_object_v), Obj1_0, Obj1),

   obj_construct(man_v, [sex, name], [man, 'Adam'], Obj2_0),
   obj_rebase((object_v -> db_object_v), Obj2_0, Obj2),

   arg(1, Obj1, Class_Id1),
   arg(1, Obj2, Class_Id2),

   assertion(Class_Id1 =:= Class_Id2),

   obj_rebase((db_object_v -> object_v), Obj2, Obj3),

   arg(1, Obj2_0, Class_Id0),
   arg(1, Obj3, Class_Id3),
   assertion(Class_Id0 =:= Class_Id3),
   assertion(Obj2_0 == Obj3).

test(obj_rebase_bug2) :-

   obj_construct(citizen_v, [sex], [man], Obj1_0),
   obj_rebase((object_v -> db_object_v), Obj1_0, Obj1),

   obj_construct(citizen_v, [sex], [man], Obj2_0),
   obj_rebase((object_v -> db_object_v), Obj2_0, Obj2),

   arg(1, Obj1, Class_Id1),
   arg(1, Obj2, Class_Id2),

   assertion(Class_Id1 =:= Class_Id2),

   obj_rebase((db_object_v -> object_v), Obj2, Obj3),

   arg(1, Obj2_0, Class_Id0),
   arg(1, Obj3, Class_Id3),
   assertion(Class_Id0 =:= Class_Id3),
   assertion(Obj2_0 == Obj3).

test(obj_rebase_bug3_1) :-

   obj_construct(db_object_v, [], [], Obj1_0),
   obj_rebase((object_v -> db_object_v), Obj1_0, Obj1),

   obj_construct(db_object_v, [], [], Obj2_0),
   obj_rebase((object_v -> db_object_v), Obj2_0, Obj2),

   arg(1, Obj1, Class_Id1),
   arg(1, Obj2, Class_Id2),

   assertion(Class_Id1 =:= Class_Id2),

   obj_rebase((db_object_v -> object_v), Obj2, Obj3),

   arg(1, Obj2_0, Class_Id0),
   arg(1, Obj3, Class_Id3),
   assertion(Class_Id0 =\= Class_Id3),

   class_primary_id(object_v, Object_V_Id),
   assertion(Obj3 == object_v(Object_V_Id)).

test(obj_rebase_bug3_2) :-

   obj_construct(citizen_v, [], [], Obj1_0),
   obj_rebase((man_v -> citizen_v), Obj1_0, Obj1),

   obj_construct(citizen_v, [], [], Obj2_0),
   obj_rebase((object_v -> man_v), Obj2_0, Obj2),

   arg(1, Obj1, Class_Id1),
   arg(1, Obj2, Class_Id2),

   assertion(Class_Id1 =:= Class_Id2).

test(obj_rebase_bug4,
     [throws(error(cant_rebase_to_object_base_v,
                   context(obj_rebase/3, _)))]) :-

   obj_construct(citizen_v, [], [], Obj1_0),
   obj_rebase((citizen_v -> object_base_v), Obj1_0, Obj1),

   obj_construct(citizen_v, [], [], Obj2_0),
   obj_rebase((citizen_v -> object_base_v), Obj2_0, Obj2),

   arg(1, Obj1, Class_Id1),
   arg(1, Obj2, Class_Id2),

   assertion(Class_Id1 =:= Class_Id2),

   obj_rebase((object_base_v -> citizen_v), Obj2, Obj3),

   arg(1, Obj2_0, Class_Id0),
   arg(1, Obj3, Class_Id3),
   assertion(Class_Id0 =:= Class_Id3),
   assertion(Obj2_0 == Obj3).

test(obj_rebase_bug5, [X == 1]) :-

   obj_construct(http_headers_v, [], [], O0),
   obj_rebase((http_headers_v
              -> http_response_headers_v), O0, O1),
   obj_rebase((http_headers_v
              -> http_invalid_bulk_headers_v), O1, O2),
   obj_rebase((http_headers_v
              -> http_response_with_cookies_headers_v),
              O2, O3),
   O3 / set_cookie ^= 1,
   obj_rebase((http_headers_v
              -> http_response_with_cookies_headers_v),
              O3, O4),
   obj_field(O4, set_cookie, X).

test(obj_reset_fields1) :-

   obj_construct(man_v,
                 [sex, name, weight, height],
                 [man, 'Simeon', 63, 1.75], Man0),

   obj_reset_fields([name, height], Man0, Man1),
   obj_class_id(Man1, Class_Id),
   assertion(Man1 =@= man_v(Class_Id, _, _, man, _, 63)),

   obj_reset_fields([weight], Man1, Man2),
   assertion(Man2 =@= man_v(Class_Id, _, _, man, _, _)),

   obj_reset_fields([], Man2, Man3),
   assertion(Man3 =@= Man2).

test(obj_reset_fields2, [fail]) :-

   obj_construct(man_v,
                 [sex, name, weight, height],
                 [man, 'Simeon', 63, 1.75], Man0),

   obj_reset_fields([name, height, age], Man0, _).

test(obj_reset_fields_weak) :-

   obj_construct(man_v,
                 [sex, name, weight, height],
                 [man, 'Simeon', 63, 1.75], Man0),

   obj_reset_fields_weak([name, height, age], Man0, Man1),
   obj_class_id(Man1, Class_Id),
   assertion(Man1 =@= man_v(Class_Id, _, _, man, _, 63)).

test(obj_reset_fields_with_evals, [fail]) :-

   obj_construct(citizen_v, [sex], [man], O),
   obj_reset_fields([age], O, _).

test(obj_rewrite) :-

   obj_construct(man_v,
                 [name, height, weight],
                 ['Luda', 1.40, 99], Luda1),
   obj_rewrite(Luda1,
               [height, weight, name],
               [Old_Height, Old_Weight, Name],
               [1.44, 69, Name],
               Luda2),
   assertion([Old_Height, Old_Weight] =@= [1.40, 99]),
   obj_rewrite(Luda2,
               [height, weight, name],
               Luda2_Pars,
               [1.45, 64, _],
               Luda3),
   assertion(Luda2_Pars =@= [1.44, 69, 'Luda']),
   named_args_unify(Luda3, [height, weight, name], Luda3_Pars),
   assertion(Luda3_Pars =@= [1.45, 64, _]).

test(obj_rewrite_weak1,
     [throws(error(no_object_field(Luda1, country), _))]) :-

   obj_construct(man_v,
                 [name, height, weight],
                 ['Luda', 1.40, 99], Luda1),
   obj_rewrite(Luda1,
               [height, weight, name, country],
               _,
               [1.44, 69, _, 'UK'],
               _).

test(obj_rewrite_weak2,
     [[Old_Height, Old_Weight, Name, Old_Country]
     =@= [1.40, 99, 'Luda', _]]
     ) :-

   obj_construct(man_v,
                 [name, height, weight],
                 ['Luda', 1.40, 99], Luda1),
   obj_rewrite(Luda1, weak,
               [height, weight, name, country],
               [Old_Height, Old_Weight, Name, Old_Country],
               [1.44, 69, Name, 'UK'],
               _).

test(obj_rewrite_weak3, [fail]) :-

   obj_construct(man_v,
                 [name, height, weight],
                 ['Luda', 1.40, 99], Luda1),
   obj_rewrite(Luda1, fail,
               [height, weight, name, country],
               _,
               [1.44, 69, _, 'UK'],
               _).

test(obj_rewrite_with_evals1, [X == callup_v]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], O),
   obj_rewrite(O, [class], [X], [callup_v], _).

test(obj_rewrite_with_evals2, [fail]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], O),
   obj_rewrite(O, [class], [_], [citizen_v], _).

test(obj_rewrite_with_evals3, [X == callup_v]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], O),
   obj_rewrite(O, [class], [X], [X], _).

test(obj_rewrite_with_evals4) :-
% <NB> can't reset eval field, compare with test(obj_rewrite)

   obj_construct(citizen_v, [sex, birthday], [man, 1994], O),
   obj_rewrite(O, [class], [_], [_], _).

test(obj_sort_parents1,
     [P4 == [http_invalid_mixed_headers_v,
             http_invalid_headers_v,
             http_request_headers_v,
             http_response_headers_v,
             http_headers_v,
             object_v, object_base_v]]
     ) :-

   obj_construct(http_request_headers_v, [], [], V1),
   obj_rebase((http_headers_v -> http_response_headers_v),
              V1, V2),
   obj_rebase((http_headers_v -> http_invalid_mixed_headers_v),
              V2, V3),

   obj_sort_parents(V3, [http_invalid_bulk_headers_v,
                         http_invalid_mixed_headers_v,
                         http_invalid_headers_v,
                         http_request_headers_v,
                         http_response_headers_v,
                         http_headers_v,
                         tarjan_vertex_v,
                         db_object_v,
                         object_v, object_base_v], V4),
   obj_parents(V4, P4),
   functor(V4, F4, _),
   assertion(F4 == http_invalid_mixed_headers_v).

test(obj_sort_parents2,
     [throws(error(insufficient_class_order(Order,
                                            Orig_Order), _))]
     ) :-

   Order = [http_invalid_bulk_headers_v,
            http_invalid_mixed_headers_v,
            http_request_headers_v,
            http_response_headers_v,
            http_headers_v,
            tarjan_vertex_v,
            db_object_v,
            object_v, object_base_v],

   obj_construct(http_request_headers_v, [], [], V1),
   obj_rebase((http_headers_v -> http_response_headers_v),
              V1, V2),
   obj_rebase((http_headers_v -> http_invalid_mixed_headers_v),
              V2, V3),

   obj_parents(V3, Orig_Order),
   obj_sort_parents(V3, Order, _).

test(obj_sort_parents_bug1) :-

   new_http_user(HTTP_User),
   obj_rebase((object_v -> citizen_v),
              HTTP_User, U1),

   class_parents(http_user_v, HTTP_User_Parents),
   append([citizen_v, man_v], HTTP_User_Parents,
          Parents_Order),

   obj_sort_parents(U1, Parents_Order, HTTP_Citizen),
   % citizen_v -> man_v -> http_user_v -> ...object_base_v

   obj_copy(HTTP_Citizen, HTTP_Citizen_Copy),
   eval_obj_expr(HTTP_Citizen / www_address / cookies_db, Key1),
   eval_obj_expr(HTTP_Citizen_Copy / www_address / cookies_db, Key2),
   assertion(Key1 \= Key2).

test(class_fields) :-

   class_fields(object_base_v, Object_Base_V_Fields),
   assertion(Object_Base_V_Fields == []),

   class_fields_new(object_base_v, Object_Base_V_New_Fields),
   assertion(Object_Base_V_New_Fields == []),

   class_fields(object_v, Object_V_Fields),
   assertion(Object_V_Fields == []),

   class_fields_new(object_v, Object_V_New_Fields),
   assertion(Object_V_New_Fields == []),

   class_fields(man_v, Man_V_Fields),
   assertion(Man_V_Fields == [height, name, sex, surname, weight]),

   class_fields_new(man_v, Man_V_New_Fields),
   assertion(Man_V_New_Fields == [height, name, sex, surname,
                                  weight]),

   class_fields(citizen_v, Citizen_V_Fields),
   assertion(Citizen_V_Fields == [birthday, country, height, id,
                                  name, sex, surname, weight]),

   class_fields_new(citizen_v, Citizen_V_New_Fields),
   assertion(Citizen_V_New_Fields == [birthday, country, id]).

test(cleanup_obj_rebase, [blocked(transaction_bug), N1 =:= N2]) :-

   aggregate(count, A^B^C^(objects:class_id(A, B, C)), N1),
   catch((obj_construct(numeric_id_v, [], [], Obj1),
          obj_rebase((object_v -> citizen_v), Obj1, _)),
         E, true),
   E = error(EX, _), functor(EX, duplicate_field, _),
   aggregate(count, A^B^C^(objects:class_id(A, B, C)), N2).

% After some time it will always fails (because it depends
% on the current year, see The Uranium Book).
test(eval_fields1, [Class == callup_v]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], C),
   obj_field(C, class, Class).

test(eval_fields2) :-

   % man_v doesn't define class eval, so in this example
   % the eval from citizen_v is always used.

   obj_construct(citizen_v,
                 [sex, birthday], [man, 1994], C1),
   obj_field(C1, class, Cl1),
   obj_parents(C1,
               [man_v, citizen_v, object_v, object_base_v],
               C2),
   obj_field(C2, class, Cl2),
   assertion(Cl1 == callup_v),
   assertion(Cl2 == callup_v).

test(eval_fields3,
     [blocked(need_to_see)]
     ) :-

   obj_construct(callup_v,
                 [sex, birthday], [man, 1994], C1),
   obj_field(C1, class, Cl1),
   obj_rebase((citizen_v -> man_v), C1, C2),
   obj_parents(C2, P2),

   % for sure, citizen_v is not present
   assertion(P2 ==
            [callup_v, man_v, object_v, object_base_v]),

   obj_field(C2, class, Cl2),
   assertion(Cl1 == callup_v),
   assertion(Cl2 == man_v).

test(eval_fields4) :-

   obj_construct(adder_v, [], [], Adder1),

   obj_unify(Adder1, [a, b, c], [3, 11, C]),
   assertion(C == 14),

   obj_unify(Adder1, [z, y, x], [2, 10, X]),
   assertion(X == 12).

test(eval_fields5) :-

   obj_construct(adder_v, [a, b, c], [3, 11, C], _),
   assertion(C == 14),

   obj_construct(adder_v, [z, y, x], [2, 10, X], _),
   assertion(X == 12).

% eval inheritance
test(eval_fields6) :-

   obj_construct(vector_adder_v, [], [], Adder1),

   obj_unify(Adder1,
             [a, b, c],
             [[2, 3], [10, 11], C]),
   assertion(C == [12, 14]),

   obj_unify(Adder1, [z, y, x], [2, 10, X]),
   assertion(X == 12).

test(eval_fields7) :-

   obj_construct(vector_adder_v,
                 [a, b, c],
                 [[2, 3], [10, 11], C],
                 _),
   assertion(C == [12, 14]),

   obj_construct(adder_v, [z, y, x], [2, 10, X], _),
   assertion(X == 12).

reload_classes :-
   current_prolog_flag(verbose, Old_Verbose),
   set_prolog_flag(verbose, silent),
   reload_all_classes,
   set_prolog_flag(verbose, Old_Verbose).

:- end_tests(v).


Adjust position of point.

Adjust position of point.

set terminal png transparent nointerlace \
    font "lucon.ttf,20" \
    size 1920,1080 nocrop \
    noenhanced \
    background '#FFFFFF'

set output "linear-1.png"
set encoding utf8

set style line 101 linetype 1 linewidth 5 linecolor rgbcolor '#000000'
set style line 102 linetype 2 linewidth 4 linecolor rgbcolor '#999999'
set style line 103 linetype 3 linewidth 4 linecolor rgbcolor '#A00000'
set style line 104 linetype 4 linewidth 4 linecolor rgbcolor '#FF0000'
set style line 105 linetype 5 linewidth 4 linecolor rgbcolor '#007000'
set style line 106 linetype 6 linewidth 6 linecolor rgbcolor '#00FF00'
set style line 107 linetype 7 linewidth 4 linecolor rgbcolor '#0000A0'
set style line 108 linetype 8 linewidth 4 linecolor rgbcolor '#1E90FF'
set style line 109 linetype 9 linewidth 4 linecolor rgbcolor '#A020F0'

set key off

# TODO: set origin and size as options or calculate.
set origin 0.02,0
set size 0.98,1
set ytics
set xtics
set border
set colorbox
set xrange [-20:-14]
set grid xtics
set mxtics
set xlabel "x" font "lucon.ttf,30"

set grid ytics
set mytics
set my2tics
set ylabel "f(x)" font "lucon.ttf,30"
#set ytics nomirror
#set y2tics nomirror
set label 1 "2005-2017 © eigenholser" \
    at screen 0.99,0.014 right font "times.ttf,12"
set label 2 "f(x) = 4x + 42" at screen 0.21,0.865 left font "times.ttf,30"
set label 3 "f(x) = α(x + 17) - 26" at screen 0.21,0.830 left font "times.ttf,30"
set title "Linear polynomials passing through point (-17,-26)" font "lucon.ttf,30"

# Greek α symbol is U03B1
f(x) = 4.0*x + 42
x1 = -17
set style line 1 pointtype 7 linecolor rgb '#000000' pointsize 4
plot \
    (-89.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (-55.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (-34.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (-21.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (-13.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (13.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (21.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (34.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (55.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (89.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    f(x) axes x1y1 not with lines linestyle 102, \
    '+' using ($0 == 0 ? x1 : NaN):(f(x1)):(sprintf('(%.1d,%.1d)', x1, f(x1))) \
    with labels offset char -3,2 left textcolor rgb 'blue' \
    point linestyle 1 notitle

set terminal png transparent nointerlace \
    font "lucon.ttf,20" \
    size 1920,1080 nocrop \
    noenhanced \
    background '#FFFFFF'

set output "linear-1.png"
set encoding utf8

set style line 101 linetype 1 linewidth 5 linecolor rgbcolor '#000000'
set style line 102 linetype 2 linewidth 4 linecolor rgbcolor '#999999'
set style line 103 linetype 3 linewidth 4 linecolor rgbcolor '#A00000'
set style line 104 linetype 4 linewidth 4 linecolor rgbcolor '#FF0000'
set style line 105 linetype 5 linewidth 4 linecolor rgbcolor '#007000'
set style line 106 linetype 6 linewidth 6 linecolor rgbcolor '#00FF00'
set style line 107 linetype 7 linewidth 4 linecolor rgbcolor '#0000A0'
set style line 108 linetype 8 linewidth 4 linecolor rgbcolor '#1E90FF'
set style line 109 linetype 9 linewidth 4 linecolor rgbcolor '#A020F0'

set key off

# TODO: set origin and size as options or calculate.
set origin 0.02,0
set size 0.98,1
set ytics
set xtics
set border
set colorbox
set xrange [-20:-14]
set grid xtics
set mxtics
set xlabel "x" font "lucon.ttf,30"

set grid ytics
set mytics
set my2tics
set ylabel "f(x)" font "lucon.ttf,30"
#set ytics nomirror
#set y2tics nomirror
set label 1 "2005-2017 © eigenholser" \
    at screen 0.99,0.014 right font "times.ttf,12"
set label 2 "f(x) = 4x + 42" at screen 0.21,0.865 left font "times.ttf,30"
set label 3 "f(x) = α(x + 17) - 26" at screen 0.21,0.830 left font "times.ttf,30"
set title "Linear polynomials passing through point (-17,-26)" font "lucon.ttf,30"

# Greek α symbol is U03B1
f(x) = 4.0*x + 42
x1 = -17
set style line 1 pointtype 7 linecolor rgb '#000000' pointsize 4
plot \
    (-89.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (-55.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (-34.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (-21.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (-13.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (13.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (21.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (34.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (55.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (89.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    f(x) axes x1y1 not with lines linestyle 102, \
    '+' using ($0 == 0 ? x1 : NaN):(f(x1)):(sprintf('(%.1d,%.1d)', x1, f(x1))) \
    with labels offset char -2,2.5 left textcolor rgb 'blue' \
    point linestyle 1 notitle


horizonatl grid added.

horizonatl grid added.

set autoscale y
set autoscale y2
set ytics nomirror
set grid ytics lc rgb "#bbbbbb" lw 1 lt 0
set y2tics
set tics out
set xlabel "Epoch"
set ylabel "Loss"
set y2label "Validation accuracy"
set key left top
plot "log.txt" using 1:2 with points axes x1y1 title 'Loss', \
     "log.txt" using 1:3 with lines axes x1y1 title 'Mean Loss', \
     "log.txt" using 1:4 with lines axes x1y1 title 'Mean2 Loss', \
     "log.txt" using 1:5 with points axes x1y2 title 'Validation accuracy', \
     "log.txt" using 1:6 with lines axes x1y2 title 'Mean Validation accuracy'
pause 1
reread

set autoscale y
set autoscale y2
set ytics nomirror
set y2tics
set tics out
set xlabel "Epoch"
set ylabel "Loss"
set y2label "Validation accuracy"
set key left top
plot "log.txt" using 1:2 with points axes x1y1 title 'Loss', \
     "log.txt" using 1:3 with lines axes x1y1 title 'Mean Loss', \
     "log.txt" using 1:4 with lines axes x1y1 title 'Mean2 Loss', \
     "log.txt" using 1:5 with points axes x1y2 title 'Validation accuracy', \
     "log.txt" using 1:6 with lines axes x1y2 title 'Mean Validation accuracy'
pause 1
reread


adding the plotting function for gnuplot.

#p "FDTD.dat"
set terminal x11 size 1250,1000
set dgrid3d 200, 200, 2
set pm3d
set palette
set palette color
set pm3d map
# set palette defined ( 0 "green", 1 "blue", 2 "red", 3 "orange" )
# set palette defined ( 0 "black", 1 "white" )
set palette defined ( 0 "blue", 1 "white", 2 "red" )
# splot "FDTD.dat" i 100 u 2:3:4
# set zrange [-1:1]

# PS: If you want to watch everything run with time, uncomment the following:
# set cbrange [-0.05:0.05]
set object circle at 150,100 size 40 fs empty border 1 front lw 5
set size ratio -1

set cbrange [-0.2:0.2]
# splot "FDTD.dat" i 100 u 2:3:4
do for [ii=1:100:1] { plot "FDTD.dat" i ii u 2:3:4 w image; pause .1}
# do for [ii=1:151:1] { splot "FDTD.dat" i ii u 2:3:4}

set object circle at 100,100 size 50 fs empty border 30 lw 30
set size ratio -1
# rep

#p "FDTD.dat"
set terminal x11 size 1250,1000
set dgrid3d 200, 200, 2
set pm3d
set palette
set palette color
set pm3d map
set palette defined ( 0 "green", 1 "blue", 2 "red", 3 "orange" )
# set palette defined ( 0 "black", 1 "white" )
# splot "FDTD.dat" i 100 u 2:3:4
# set zrange [-1:1]

# PS: If you want to watch everything run with time, uncomment the following:
# set cbrange [-0.05:0.05]
set object circle at 150,150 size 50 fs empty border 1 front lw 5
set size ratio -1

set cbrange [-0.5:0.5]
splot "FDTD.dat" i 100 u 2:3:4 w l
# do for [ii=1:151:1] { splot "FDTD.dat" i ii u 2:3:4}

set object circle at 100,100 size 50 fs empty border 30 lw 30
set size ratio -1
# rep


20160405T2046

#!/usr/bin/env gnuplot

# graph of CPU temperature

# datafile
ifname = "/tmp/sql11.csv"
ofname = "/tmp/lnxdiagd/site/img/day11.png"

# ******************************************************* General settings *****
# set terminal png font "Vera" 11 size 640,480
set terminal png font "Courier" 10 size 640,304
set datafile separator ';'
set datafile missing "NaN"    # Ignore missing values
set grid
tz_offset = utc_offset / 3600 # GNUplot only works with UTC. Need to compensate
                              # for timezone ourselves.
set timestamp 'created: %Y-%m-%d %H:%M' bottom

# ************************************************************* Statistics *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifname using 2 name "X" nooutput

X_min = X_min + utc_offset - 946684800
X_max = X_max + utc_offset - 946684800

# ****************************************************************** Title *****
set title "CPU Temperature"
#"-".utc_offset."-"

# ***************************************************************** X-axis *****
set xlabel "Date/Time"       # X-axis label
set xdata time               # Define that data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xtics rotate by 40 right
set xrange [ X_min : X_max ]

# ***************************************************************** Y-axis *****
set ylabel "Temperature [degC]"
#set yrange [10:20]
set autoscale y

# **************************************************************** Y2-axis *****
# set y2label "Temperature [degC]"
# set autoscale y2
# set y2tics border

# ***************************************************************** Legend *****
# generate a legend which is placed underneath the plot
#set key outside bottom center box title "-=legend=-"
set key default
set key box
set key samplen .2
set key inside vertical
set key left top

# ***************************************************************** Output *****
set arrow from graph 0,graph 0 to graph 0,graph 1 nohead lc rgb "red" front
#set arrow from graph 1,graph 0 to graph 1,graph 1 nohead lc rgb "green" front
set object 1 rect from screen 0,0 to screen 1,1 behind
set object 1 rect fc rgb "#eeeeee" fillstyle solid 1.0 noborder
set object 2 rect from graph 0,0 to graph 1,1 behind
set object 2 rect fc rgb "#ffffff" fillstyle solid 1.0 noborder
set output ofname

# ***** PLOT *****
plot ifname  using ($2+utc_offset):4 title " Temperature [degC]" with points pt 5 ps 0.2 \
#    ,       using ($2+utc_offset):4 title " Temperature [degC]" axes x1y2  with dots\

#!/usr/bin/env gnuplot

# graph of CPU temperature

# datafile
ifname = "/tmp/sql11.csv"
ofname = "/tmp/lnxdiagd/site/img/day11.png"

# ******************************************************* General settings *****
# set terminal png font "Vera" 11 size 640,480
set terminal png font "Courier" 10 size 480,228
set datafile separator ';'
set datafile missing "NaN"    # Ignore missing values
set grid
tz_offset = utc_offset / 3600 # GNUplot only works with UTC. Need to compensate
                              # for timezone ourselves.
set timestamp 'created: %Y-%m-%d %H:%M' bottom

# ************************************************************* Statistics *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifname using 2 name "X" nooutput

X_min = X_min + utc_offset - 946684800
X_max = X_max + utc_offset - 946684800

# ****************************************************************** Title *****
set title "CPU Temperature"
#"-".utc_offset."-"

# ***************************************************************** X-axis *****
set xlabel "Date/Time"       # X-axis label
set xdata time               # Define that data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xtics rotate by 40 right
set xrange [ X_min : X_max ]

# ***************************************************************** Y-axis *****
set ylabel "Temperature [degC]"
#set yrange [10:20]
set autoscale y

# **************************************************************** Y2-axis *****
# set y2label "Temperature [degC]"
# set autoscale y2
# set y2tics border

# ***************************************************************** Legend *****
# generate a legend which is placed underneath the plot
#set key outside bottom center box title "-=legend=-"
set key default
set key box
set key samplen .2
set key inside vertical
set key left top

# ***************************************************************** Output *****
set arrow from graph 0,graph 0 to graph 0,graph 1 nohead lc rgb "red" front
#set arrow from graph 1,graph 0 to graph 1,graph 1 nohead lc rgb "green" front
set object 1 rect from screen 0,0 to screen 1,1 behind
set object 1 rect fc rgb "#eeeeee" fillstyle solid 1.0 noborder
set object 2 rect from graph 0,0 to graph 1,1 behind
set object 2 rect fc rgb "#ffffff" fillstyle solid 1.0 noborder
set output ofname

# ***** PLOT *****
plot ifname  using ($2+utc_offset):4 title " Temperature [degC]" with points pt 5 ps 0.2 \
#    ,       using ($2+utc_offset):4 title " Temperature [degC]" axes x1y2  with dots\


scaling on

scaling on

#!/usr/bin/env gnuplot

# graph of CPU temperature

# datafile
ifname = "/tmp/sql11.csv"
ofname = "/tmp/lnxdiagd/site/img/day11.png"

# ******************************************************* General settings *****
# set terminal png font "Vera" 11 size 640,480
set terminal png truecolor enhanced font "Vera" 10 size 640,304
set datafile separator ';'
set datafile missing "NaN"    # Ignore missing values
set grid
tz_offset = utc_offset / 3600 # GNUplot only works with UTC. Need to compensate
                              # for timezone ourselves.
set timestamp 'created: %Y-%m-%d %H:%M' bottom font "Vera,8"

# ************************************************************* Statistics *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifname using 2 name "X" nooutput

X_min = X_min + utc_offset - 946684800
X_max = X_max + utc_offset - 946684800

# stats to be calculated here for Y-axis
stats ifname using 4 name "Y" nooutput
Y_min = Y_min * 0.90
Y_max = Y_max * 1.10

# ****************************************************************** Title *****
set title "CPU Temperature"
#"-".utc_offset."-"

# ***************************************************************** X-axis *****
set xlabel "Date/Time"       # X-axis label
set xdata time               # Define that data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xtics rotate by 40 right
set xrange [ X_min : X_max ]

# ***************************************************************** Y-axis *****
set ylabel "Temperature [degC]"
#set yrange [10:20]
#set autoscale y
set yrange [ Y_min : Y_max ]

# **************************************************************** Y2-axis *****
# set y2label "Temperature [degC]"
# set autoscale y2
# set y2tics border

# ***************************************************************** Legend *****
set key outside bottom center horizontal box
set key samplen .5
set key reverse Left

# ***************************************************************** Output *****
set arrow from graph 0,graph 0 to graph 0,graph 1 nohead lc rgb "red" front
#set arrow from graph 1,graph 0 to graph 1,graph 1 nohead lc rgb "green" front
set object 1 rect from screen 0,0 to screen 1,1 behind
set object 1 rect fc rgb "#eeeeee" fillstyle solid 1.0 noborder
set object 2 rect from graph 0,0 to graph 1,1 behind
set object 2 rect fc rgb "#ffffff" fillstyle solid 1.0 noborder
set output ofname

# ***** PLOT *****
plot ifname  using ($2+utc_offset):4 title " Temperature [degC]" with points pt 5 ps 0.1 fc rgb "#ccbb0000" \

#!/usr/bin/env gnuplot

# graph of CPU temperature

# datafile
ifname = "/tmp/sql11.csv"
ofname = "/tmp/lnxdiagd/site/img/day11.png"

# ******************************************************* General settings *****
# set terminal png font "Vera" 11 size 640,480
set terminal png truecolor enhanced font "Vera" 10 size 640,304
set datafile separator ';'
set datafile missing "NaN"    # Ignore missing values
set grid
tz_offset = utc_offset / 3600 # GNUplot only works with UTC. Need to compensate
                              # for timezone ourselves.
set timestamp 'created: %Y-%m-%d %H:%M' bottom font "Vera,8"

# ************************************************************* Statistics *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifname using 2 name "X" nooutput

X_min = X_min + utc_offset - 946684800
X_max = X_max + utc_offset - 946684800

# stats to be calculated here for Y-axis
stats ifname using 4 name "Y" nooutput
Y_min = Y_min * 0.90
Y_max = Y_max * 1.10

# ****************************************************************** Title *****
set title "CPU Temperature"
#"-".utc_offset."-"

# ***************************************************************** X-axis *****
set xlabel "Date/Time"       # X-axis label
set xdata time               # Define that data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xtics rotate by 40 right
set xrange [ X_min : X_max ]

# ***************************************************************** Y-axis *****
set ylabel "Temperature [degC]"
#set yrange [10:20]
set autoscale y

# **************************************************************** Y2-axis *****
# set y2label "Temperature [degC]"
# set autoscale y2
# set y2tics border

# ***************************************************************** Legend *****
set key outside bottom center horizontal box
set key samplen .5
set key reverse Left

# ***************************************************************** Output *****
set arrow from graph 0,graph 0 to graph 0,graph 1 nohead lc rgb "red" front
#set arrow from graph 1,graph 0 to graph 1,graph 1 nohead lc rgb "green" front
set object 1 rect from screen 0,0 to screen 1,1 behind
set object 1 rect fc rgb "#eeeeee" fillstyle solid 1.0 noborder
set object 2 rect from graph 0,0 to graph 1,1 behind
set object 2 rect fc rgb "#ffffff" fillstyle solid 1.0 noborder
set output ofname

# ***** PLOT *****
plot ifname  using ($2+utc_offset):4 title " Temperature [degC]" with points pt 5 ps 0.1 fc rgb "#ccbb0000" \


Update F4_03someGnuplot.gp so that it conforms with new gnuplot 5.4 Checked with  gnuplot F4_03someGnuplot.gp  --persist

#!/usr/bin/gnuplot -persist
#
#
#    	G N U P L O T
#    	Version 5.0 patchlevel 0    last modified 2015-01-01
#
#    	Copyright (C) 1986-1993, 1998, 2004, 2007-2015
#    	Thomas Williams, Colin Kelley and many others
#
#    	gnuplot home:     http://www.gnuplot.info
#    	faq, bugs, etc:   type "help FAQ"
#    	immediate help:   type "help"  (plot window: hit 'h')
#
#    	Type `load "all.dem"` to display a large number of examples.
#    	They are located at /usr/share/doc/packages/gnuplot/demo/*
#
# set terminal qt 0 font "Sans,9"
# set output
unset clip points
set clip one
unset clip two
set bar 1.000000 front
set border 31 front lt black linewidth 1.000 dashtype solid
set zdata
set ydata
set xdata
set y2data
set x2data
set boxwidth
set style fill  empty border
set style rectangle back fc  bgnd fillstyle   solid 1.00 border lt -1
set style circle radius graph 0.02, first 0.00000, 0.00000
set style ellipse size graph 0.05, 0.03, first 0.00000 angle 0 units xy
set dummy x, y
set format x "% h"
set format y "% h"
set format x2 "% h"
set format y2 "% h"
set format z "% h"
set format cb "% h"
set format r "% h"
set timefmt "%d/%m/%y,%H:%M"
set angles radians
unset grid
set raxis
set style parallel front  lt black linewidth 2.000 dashtype solid
set key title ""
set key inside right top vertical Right noreverse enhanced autotitle nobox
set key noinvert samplen 4 spacing 1 width 0 height 0
set key maxcolumns 0 maxrows 0
set key noopaque
unset label
unset arrow
set style increment default
unset style line
unset style arrow
set style histogram clustered gap 2 title textcolor lt -1
unset object
set style textbox transparent margins  1.0,  1.0 border
unset logscale
set offsets 0, 0, 0, 0
set pointsize 1
set pointintervalbox 1
set encoding default
unset polar
unset parametric
unset decimalsign
set view 60, 30, 1, 1
set samples 500, 500
set isosamples 10, 10
set surface
unset contour
set cntrlabel  format '%8.3g' font '' start 5 interval 20
set mapping cartesian
set datafile separator whitespace
unset hidden3d
set cntrparam order 4
set cntrparam linear
set cntrparam levels auto 5
set cntrparam points 5
set size ratio 0 1,1
set origin 0,0
set style data points
set style function lines
unset xzeroaxis
unset yzeroaxis
unset zzeroaxis
unset x2zeroaxis
unset y2zeroaxis
set ticslevel 0.5
set tics scale  1, 0.5, 1, 1, 1
set mxtics default
set mytics default
set mztics default
set mx2tics default
set my2tics default
set mcbtics default
set mrtics default
set xtics border in scale 1,0.5 mirror norotate  autojustify
set xtics autofreq  norangelimit
set ytics border in scale 1,0.5 mirror norotate  autojustify
set ytics autofreq  norangelimit
set ztics border in scale 1,0.5 nomirror norotate  autojustify
set ztics autofreq  norangelimit
unset x2tics
unset y2tics
set cbtics border in scale 1,0.5 mirror norotate  autojustify
set cbtics autofreq  norangelimit
set rtics axis in scale 1,0.5 nomirror norotate  autojustify
set rtics autofreq  norangelimit
unset paxis 1 tics
unset paxis 2 tics
unset paxis 3 tics
unset paxis 4 tics
unset paxis 5 tics
unset paxis 6 tics
unset paxis 7 tics
set title ""
set title  font "" norotate
set timestamp bottom
set timestamp ""
set timestamp  font "" norotate
set rrange [ * : * ] noreverse nowriteback
set trange [ * : * ] noreverse nowriteback
set urange [ * : * ] noreverse nowriteback
set vrange [ * : * ] noreverse nowriteback
set xlabel ""
set xlabel  font "" textcolor lt -1 norotate
set x2label ""
set x2label  font "" textcolor lt -1 norotate
set xrange [ * : * ] noreverse nowriteback
set x2range [ * : * ] noreverse nowriteback
set ylabel ""
set ylabel  font "" textcolor lt -1 rotate by -270
set y2label ""
set y2label  font "" textcolor lt -1 rotate by -270
set yrange [ * : * ] noreverse nowriteback
set y2range [ * : * ] noreverse nowriteback
set zlabel ""
set zlabel  font "" textcolor lt -1 norotate
set zrange [ * : * ] noreverse nowriteback
set cblabel ""
set cblabel  font "" textcolor lt -1 rotate by -270
set cbrange [ * : * ] noreverse nowriteback
set paxis 1 range [ * : * ] noreverse nowriteback
set paxis 2 range [ * : * ] noreverse nowriteback
set paxis 3 range [ * : * ] noreverse nowriteback
set paxis 4 range [ * : * ] noreverse nowriteback
set paxis 5 range [ * : * ] noreverse nowriteback
set paxis 6 range [ * : * ] noreverse nowriteback
set paxis 7 range [ * : * ] noreverse nowriteback
set zero 1e-08
set lmargin  -1
set bmargin  -1
set rmargin  -1
set tmargin  -1
set locale "en_US.UTF-8"
set pm3d explicit at s
set pm3d scansautomatic
set pm3d interpolate 1,1 flush begin noftriangles noborder corners2color mean
set palette positive nops_allcF maxcolors 0 gamma 1.5 color model RGB
set palette rgbformulae 7, 5, 15
set colorbox default
set colorbox vertical origin screen 0.9, 0.2, 0 size screen 0.05, 0.6, 0 front bdefault
set style boxplot candles range  1.50 outliers pt 7 separation 1 labels auto unsorted
set loadpath
set fontpath
set psdir
set fit brief errorvariables nocovariancevariables errorscaling prescale nowrap v5
f(x)=a*sin(x)
GNUTERM = "qt"
ARGC = 0
ARG0 = ""
a = 4
#GPFUN_f = "f(x)=a*sin(x)"
plot f(x)
#    EOF

#!/usr/bin/gnuplot -persist
#
#
#    	G N U P L O T
#    	Version 5.0 patchlevel 0    last modified 2015-01-01
#
#    	Copyright (C) 1986-1993, 1998, 2004, 2007-2015
#    	Thomas Williams, Colin Kelley and many others
#
#    	gnuplot home:     http://www.gnuplot.info
#    	faq, bugs, etc:   type "help FAQ"
#    	immediate help:   type "help"  (plot window: hit 'h')
#
#    	Type `load "all.dem"` to display a large number of examples.
#    	They are located at /usr/share/doc/packages/gnuplot/demo/*
#
# set terminal qt 0 font "Sans,9"
# set output
unset clip points
set clip one
unset clip two
set bar 1.000000 front
set border 31 front lt black linewidth 1.000 dashtype solid
set zdata
set ydata
set xdata
set y2data
set x2data
set boxwidth
set style fill  empty border
set style rectangle back fc  bgnd fillstyle   solid 1.00 border lt -1
set style circle radius graph 0.02, first 0.00000, 0.00000
set style ellipse size graph 0.05, 0.03, first 0.00000 angle 0 units xy
set dummy x, y
set format x "% h"
set format y "% h"
set format x2 "% h"
set format y2 "% h"
set format z "% h"
set format cb "% h"
set format r "% h"
set timefmt "%d/%m/%y,%H:%M"
set angles radians
unset grid
set raxis
set style parallel front  lt black linewidth 2.000 dashtype solid
set key title ""
set key inside right top vertical Right noreverse enhanced autotitle nobox
set key noinvert samplen 4 spacing 1 width 0 height 0
set key maxcolumns 0 maxrows 0
set key noopaque
unset label
unset arrow
set style increment default
unset style line
unset style arrow
set style histogram clustered gap 2 title textcolor lt -1
unset object
set style textbox transparent margins  1.0,  1.0 border
unset logscale
set offsets 0, 0, 0, 0
set pointsize 1
set pointintervalbox 1
set encoding default
unset polar
unset parametric
unset decimalsign
set view 60, 30, 1, 1
set samples 500, 500
set isosamples 10, 10
set surface
unset contour
set cntrlabel  format '%8.3g' font '' start 5 interval 20
set mapping cartesian
set datafile separator whitespace
unset hidden3d
set cntrparam order 4
set cntrparam linear
set cntrparam levels auto 5
set cntrparam points 5
set size ratio 0 1,1
set origin 0,0
set style data points
set style function lines
unset xzeroaxis
unset yzeroaxis
unset zzeroaxis
unset x2zeroaxis
unset y2zeroaxis
set ticslevel 0.5
set tics scale  1, 0.5, 1, 1, 1
set mxtics default
set mytics default
set mztics default
set mx2tics default
set my2tics default
set mcbtics default
set mrtics default
set xtics border in scale 1,0.5 mirror norotate  autojustify
set xtics autofreq  norangelimit
set ytics border in scale 1,0.5 mirror norotate  autojustify
set ytics autofreq  norangelimit
set ztics border in scale 1,0.5 nomirror norotate  autojustify
set ztics autofreq  norangelimit
unset x2tics
unset y2tics
set cbtics border in scale 1,0.5 mirror norotate  autojustify
set cbtics autofreq  norangelimit
set rtics axis in scale 1,0.5 nomirror norotate  autojustify
set rtics autofreq  norangelimit
unset paxis 1 tics
unset paxis 2 tics
unset paxis 3 tics
unset paxis 4 tics
unset paxis 5 tics
unset paxis 6 tics
unset paxis 7 tics
set title ""
set title  font "" norotate
set timestamp bottom
set timestamp ""
set timestamp  font "" norotate
set rrange [ * : * ] noreverse nowriteback
set trange [ * : * ] noreverse nowriteback
set urange [ * : * ] noreverse nowriteback
set vrange [ * : * ] noreverse nowriteback
set xlabel ""
set xlabel  font "" textcolor lt -1 norotate
set x2label ""
set x2label  font "" textcolor lt -1 norotate
set xrange [ * : * ] noreverse nowriteback
set x2range [ * : * ] noreverse nowriteback
set ylabel ""
set ylabel  font "" textcolor lt -1 rotate by -270
set y2label ""
set y2label  font "" textcolor lt -1 rotate by -270
set yrange [ * : * ] noreverse nowriteback
set y2range [ * : * ] noreverse nowriteback
set zlabel ""
set zlabel  font "" textcolor lt -1 norotate
set zrange [ * : * ] noreverse nowriteback
set cblabel ""
set cblabel  font "" textcolor lt -1 rotate by -270
set cbrange [ * : * ] noreverse nowriteback
set paxis 1 range [ * : * ] noreverse nowriteback
set paxis 2 range [ * : * ] noreverse nowriteback
set paxis 3 range [ * : * ] noreverse nowriteback
set paxis 4 range [ * : * ] noreverse nowriteback
set paxis 5 range [ * : * ] noreverse nowriteback
set paxis 6 range [ * : * ] noreverse nowriteback
set paxis 7 range [ * : * ] noreverse nowriteback
set zero 1e-08
set lmargin  -1
set bmargin  -1
set rmargin  -1
set tmargin  -1
set locale "en_US.UTF-8"
set pm3d explicit at s
set pm3d scansautomatic
set pm3d interpolate 1,1 flush begin noftriangles noborder corners2color mean
set palette positive nops_allcF maxcolors 0 gamma 1.5 color model RGB
set palette rgbformulae 7, 5, 15
set colorbox default
set colorbox vertical origin screen 0.9, 0.2, 0 size screen 0.05, 0.6, 0 front bdefault
set style boxplot candles range  1.50 outliers pt 7 separation 1 labels auto unsorted
set loadpath
set fontpath
set psdir
set fit brief errorvariables nocovariancevariables errorscaling prescale nowrap v5
f(x)=a*sin(x)
GNUTERM = "qt"
ARGC = 0
ARG0 = ""
a = 4
GPFUN_f = "f(x)=a*sin(x)"
plot f(x)
#    EOF


Add more remove_options UTs

Add more remove_options UTs


invisible changes in this plot

invisible changes in this plot

git-svn-id: 0ef30dc7da0b07cedfa074587325a6c153c0ae55@14273 fdbf22ae-c210-0410-be80-ca943da6b8f8


After reading further into the gcc manual, I noticed that -Wunused enables all
four flags I added in my previous commit. When changing it to the shorter
single option, I noticed that we had -Wno-unused - the opposite of what we'd
like. Remove it and add an explicit -Wunused even though it comes with -Wall.

git-svn-id: 88467cb1fb04b8a755be7e1ee1026be4190196ef@12943 3a8e244f-b0f2-452b-bcba-4c88e055c3ca

#
# settings for gnu-compatible platforms
#

#
# Tools
#
CXX = g++
CC = gcc
MAKEDEPEND = $(CXX) -MM -MG
CMAKEDEPEND = $(CC) -MM -MG

RANLIB = ranlib

#
# General Flags
#

DEBUG_CFLAGS = -g
OPT_CFLAGS = -O3
PROFILE_CFLAGS = -pg
PROFILE_LFLAGS = -pg

ifdef CHPL_GCOV
CFLAGS += -fprofile-arcs -ftest-coverage
LDFLAGS += -fprofile-arcs
endif

#
# Flags for compiler, runtime, and generated code
#

COMP_CFLAGS = $(CFLAGS)
COMP_CFLAGS_NONCHPL = -Wno-error
RUNTIME_CFLAGS = $(CFLAGS)
GEN_CFLAGS = -std=c99

#
# Flags for turning on warnings for C++/C code
#
WARN_CXXFLAGS = -Wall -Werror -Wunused -Wpointer-arith -Wwrite-strings
WARN_CFLAGS = $(WARN_CXXFLAGS) -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wnested-externs -Wdeclaration-after-statement

GNU_GCC_MAJOR_VERSION = $(shell $(CC) -dumpversion | awk '{split($$1,a,"."); printf("%s", a[1]);}')
GNU_GCC_MINOR_VERSION = $(shell $(CC) -dumpversion | awk '{split($$1,a,"."); printf("%s", a[2]);}')

#
# this is fragile, but version 3.3.4 doesn't support these flags
#
ifeq ($(GNU_GCC_MAJOR_VERSION),3)
ifeq ($(GNU_GCC_MINOR_VERSION),4)
WARN_CFLAGS += -Wdeclaration-after-statement -Wnested-externs
endif
endif

#
# developer settings
#
ifdef CHPL_DEVELOPER
COMP_CFLAGS += $(WARN_CXXFLAGS)
RUNTIME_CFLAGS += $(WARN_CFLAGS)
endif

#
# settings for gnu-compatible platforms
#

#
# Tools
#
CXX = g++
CC = gcc
MAKEDEPEND = $(CXX) -MM -MG
CMAKEDEPEND = $(CC) -MM -MG

RANLIB = ranlib

#
# General Flags
#

DEBUG_CFLAGS = -g
OPT_CFLAGS = -O3
PROFILE_CFLAGS = -pg
PROFILE_LFLAGS = -pg

ifdef CHPL_GCOV
CFLAGS += -fprofile-arcs -ftest-coverage
LDFLAGS += -fprofile-arcs
endif

#
# Flags for compiler, runtime, and generated code
#

COMP_CFLAGS = $(CFLAGS)
COMP_CFLAGS_NONCHPL = -Wno-error
RUNTIME_CFLAGS = $(CFLAGS)
GEN_CFLAGS = -std=c99

#
# Flags for turning on warnings for C++/C code
#
WARN_CXXFLAGS = -Wall -Werror -Wno-unused -Wpointer-arith -Wwrite-strings -Wunused-function -Wunused-label -Wunused-value -Wunused-variable
WARN_CFLAGS = $(WARN_CXXFLAGS) -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wnested-externs -Wdeclaration-after-statement -Wunused-function -Wunused-label -Wunused-value -Wunused-variable

GNU_GCC_MAJOR_VERSION = $(shell $(CC) -dumpversion | awk '{split($$1,a,"."); printf("%s", a[1]);}')
GNU_GCC_MINOR_VERSION = $(shell $(CC) -dumpversion | awk '{split($$1,a,"."); printf("%s", a[2]);}')

#
# this is fragile, but version 3.3.4 doesn't support these flags
#
ifeq ($(GNU_GCC_MAJOR_VERSION),3)
ifeq ($(GNU_GCC_MINOR_VERSION),4)
WARN_CFLAGS += -Wdeclaration-after-statement -Wnested-externs
endif
endif

#
# developer settings
#
ifdef CHPL_DEVELOPER
COMP_CFLAGS += $(WARN_CXXFLAGS)
RUNTIME_CFLAGS += $(WARN_CFLAGS)
endif