bpm2bps

#!/usr/bin/env gnuplot

# graph of CPU load

# datafile
ifname = "/tmp/sql13.csv"
ofname = "/tmp/lnxdiagd/site/img/day13.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 front
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

stats ifname using 7 name "upY" nooutput
Y_max = upY_max * 1.1 * 8/60

stats ifname using 6 name "dnY" nooutput
Y_min = dnY_max * -1.1 * 8/60

# ************************************************************* Functions ******
# determine delta data
delta(x) = ( xD = x - old_x, old_x = x, xD < 0 ? 0 : xD)
old_x = NaN

# ****************************************************************** Title *****
set title "Network Usage (eth0)"

# ***************************************************************** 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 "Usage []"
set yrange [:100]
set autoscale y
set format y "%3.0s %c"
set yrange [ Y_min : Y_max ]

# **************************************************************** Y2-axis *****
# set y2label "Load"
# set autoscale y2
# set y2tics border

# ***************************************************************** Legend *****
set key outside bottom center horizontal box
set key samplen .2
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 *****
set style data boxes
set style fill transparent solid 0.05 noborder

plot ifname \
       using ($2+utc_offset):(delta($6)*-1*8/60) title "Download (eth0)" fc rgb "#33bb0000"  \
  , '' using ($2+utc_offset):(delta($7)*8/60)    title "Upload   (eth0)" fc rgb "#330000bb" \

#!/usr/bin/env gnuplot

# graph of CPU load

# datafile
ifname = "/tmp/sql13.csv"
ofname = "/tmp/lnxdiagd/site/img/day13.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 front
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

stats ifname using 7 name "upY" nooutput
Y_max = upY_max * 1.1

stats ifname using 6 name "dnY" nooutput
Y_min = dnY_max * -1.1

# ************************************************************* Functions ******
# determine delta data
delta(x) = ( xD = x - old_x, old_x = x, xD < 0 ? 0 : xD)
old_x = NaN

# ****************************************************************** Title *****
set title "Network Usage (eth0)"

# ***************************************************************** 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 "Usage []"
set yrange [:100]
set autoscale y
set format y "%3.0s %c"
set yrange [ Y_min : Y_max ]

# **************************************************************** Y2-axis *****
# set y2label "Load"
# set autoscale y2
# set y2tics border

# ***************************************************************** Legend *****
set key outside bottom center horizontal box
set key samplen .2
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 *****
set style data boxes
set style fill transparent solid 0.05 noborder

plot ifname \
       using ($2+utc_offset):(delta($6)*-1*8/60) title "Download (eth0)" fc rgb "#33bb0000"  \
  , '' using ($2+utc_offset):(delta($7)*8/60)    title "Upload   (eth0)" fc rgb "#330000bb" \


adding the plotting functions to github

adding the plotting functions to github

#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

#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" )
splot "FDTD.dat" i 100 u 2:3:4

# PS: If you want to watch everything run with time, uncomment the following:
# set cbrange [-0.1:0.1]
# do for [ii=1:101:1] { splot "FDTD.dat" i ii u 2:3:4 }


Tweaked cavity.plt.

Tweaked cavity.plt.

# Script to plot the cavity multipole field maps.
#
# Author: Johan Bengtsson.

home_dir = '/home/bengtsson/FRIB/Cavity Model/';

# Terminal type is: 0 - X11, 1 - PS, 2 - PNG, 3 - JPG
term_type = 0;

# On-axis long. E-field [V/m] vs. z [mm].
file1 = home_dir."axisData_41.txt";

# Transverse higher order E-field [V/m] ([V] for dipole) vs. z [mm].
# Dipole.
file2 = home_dir."Multipole41/CaviMlp_EDipole_41.txt";
# First half of defocusing component.
file3 = home_dir."Multipole41/CaviMlp_EFocus1_41.txt";
# Second half of defocusing component.
file4 = home_dir."Multipole41/CaviMlp_EFocus2_41.txt";
# Quadrupole.
file5 = home_dir."Multipole41/CaviMlp_EQuad_41.txt";

# Tranverse higher order H-field [A/m] ([A] for dipole) vs. z [mm]
file6 = home_dir."Multipole41/CaviMlp_HDipole_41.txt";
file7 = home_dir."Multipole41/CaviMlp_HMono_41.txt";
file8 = home_dir."Multipole41/CaviMlp_HQuad_41.txt";
file9 = home_dir."Multipole41/thinlenlon_41.txt";

if (term_type == 0) set terminal x11;
if (term_type == 1) set terminal postscript landscape enhanced color solid \
  lw 2 "Times-Roman" 15;
#if (term_type == 2) set terminal pngcairo size 350, 262 enhanced \
#  font 'Verdana,10';
if (term_type == 2) set terminal pngcairo enhanced font "Times-Roman";
if (term_type == 3) set terminal jpeg enhanced;

set grid;

set style line 1 lt 1 lw 1 lc rgb "blue";
set style line 2 lt 1 lw 1 lc rgb "cyan";
set style line 3 lt 1 lw 1 lc rgb "green";
set style line 4 lt 1 lw 1 lc rgb "red";
set style line 5 lt 1 lw 1 lc rgb "dark-green";
set style line 6 lt 1 lw 1 lc rgb "dark-orange";
set style line 7 lt 1 lw 1 lc rgb "dark-violet";
set style line 8 lt 1 lw 1 lc rgb "orange-red";

if (term_type == 1) set output "cavity_1.ps"
if (term_type == 2) set output "cavity_1.png"
if (term_type == 3) set output "cavity_1.jpg"

set title "Cavity Fundamental Mode: axisData";
set xlabel "z [cm]"; set ylabel "E_{/Symbol \174\174} [MV/m]";
plot file1 using (1e-1*$1):(1e-6*$2) notitle with lines ls 1;

if (term_type == 0) pause mouse "click on graph to cont.\n";

if (term_type == 1) set output "cavity_2.ps"
if (term_type == 2) set output "cavity_2.png"
if (term_type == 3) set output "cavity_2.jpg"

set multiplot;

set size 0.5, 0.5; set origin 0.0, 0.5;
set title "Cavity Mode: EDipole";
set xlabel "z [cm]"; set ylabel "E_{/Symbol \\136} [MV]";
plot file2 using (1e-1*$1):(1e-6*$2) notitle with lines ls 3;

set origin 0.5, 0.5;
set title "Cavity Mode: EQuad";
set xlabel "z [cm]"; set ylabel "E_{/Symbol \\136} [MV/m]";
plot file5 using (1e-1*$1):(1e-6*$2) notitle with lines ls 3;

set origin 0.0, 0.0;
set title "Cavity: EFocus1 & EFocus2";
set xlabel "z [cm]"; set ylabel "E_{/Symbol \\136} [MV/m]";
plot file3 using (1e-1*$1):(1e-6*$2) notitle with lines ls 3, \
     file4 using (1e-1*$1):(1e-6*$2) notitle with lines ls 3;

unset multiplot;
if (term_type == 0) pause mouse "click on graph to cont.\n";

if (term_type == 1) set output "cavity_3.ps"
if (term_type == 2) set output "cavity_3.png"
if (term_type == 3) set output "cavity_3.jpg"

set multiplot;

set size 0.5, 0.5; set origin 0.0, 0.5;
set title "Cavity Mode: HDipole";
set xlabel "z [cm]"; set ylabel "H_{/Symbol \\136} [kA]";
plot file6 using (1e-1*$1):(1e-3*$2) notitle with lines ls 3;

set origin 0.5, 0.5;
set title "Cavity Mode: HMono";
set xlabel "z [cm]"; set ylabel "H_{/Symbol \\136} [kA/m]";
plot file7 using (1e-1*$1):(1e-3*$2) notitle with lines ls 3;

set origin 0.0, 0.0;
set title "Cavity Mode: HQuad";
set xlabel "z [cm]"; set ylabel "H_{/Symbol \\136} [kA/m]";
plot file8 using (1e-1*$1):(1e-3*$2) notitle with lines ls 3;

unset multiplot;
if (term_type == 0) pause mouse "click on graph to cont.\n";

if (term_type == 1) set output "cavity_4.ps"
if (term_type == 2) set output "cavity_4.png"
if (term_type == 3) set output "cavity_4.jpg"

set size 1.0, 1.0; set origin 0.0, 0.0;
set title "Cavity Thin Lens Model: {/Symbol \\362}Eds,  {/Symbol \\362}Hds";
set xlabel "z [cm]";
set ylabel "[MV, MV/m, MA, MA/m]";
set yrange [-0.01:];
plot file9 using (1e-1*($1+$4/2.0)):6:(1e-1*$4) notitle with boxes ls 3;
if (term_type == 0) pause mouse "click on graph to cont.\n";

# Terminal type is: 0 - X11, 1 - PS, 2 - PNG, 3 - JPG
term_type = 0;

# On-axis long. E-field [V/m] vs. z [mm].
file1 = "axisData_41.txt";

# Transverse higher order E-field [V/m] ([V] for dipole) vs. z [mm].
# Dipole.
file2 = "Multipole41/CaviMlp_EDipole_41.txt";
# First half of defocusing component.
file3 = "Multipole41/CaviMlp_EFocus1_41.txt";
# Second half of defocusing component.
file4 = "Multipole41/CaviMlp_EFocus2_41.txt";
# Quadrupole.
file5 = "Multipole41/CaviMlp_EQuad_41.txt";

# Tranverse higher order H-field [A/m] ([A] for dipole) vs. z [mm]
file6 = "Multipole41/CaviMlp_HDipole_41.txt";
file7 = "Multipole41/CaviMlp_HMono_41.txt";
file8 = "Multipole41/CaviMlp_HQuad_41.txt";
file9 = "Multipole41/thinlenlon_41.txt";

if (term_type == 0) set terminal x11;
if (term_type == 1) set terminal postscript landscape enhanced color solid \
  lw 2 "Times-Roman" 15;
#if (term_type == 2) set terminal pngcairo size 350, 262 enhanced \
#  font 'Verdana,10';
if (term_type == 2) set terminal pngcairo enhanced font "Times-Roman";
if (term_type == 3) set terminal jpeg enhanced;

set grid;

set style line 1 lt 1 lw 1 lc rgb "blue";
set style line 2 lt 1 lw 1 lc rgb "cyan";
set style line 3 lt 1 lw 1 lc rgb "green";
set style line 4 lt 1 lw 1 lc rgb "red";
set style line 5 lt 1 lw 1 lc rgb "dark-green";
set style line 6 lt 1 lw 1 lc rgb "dark-orange";
set style line 7 lt 1 lw 1 lc rgb "dark-violet";
set style line 8 lt 1 lw 1 lc rgb "orange-red";

if (term_type == 1) set output "cavity_1.ps"
if (term_type == 2) set output "cavity_1.png"
if (term_type == 3) set output "cavity_1.jpg"

set title "Cavity Fundamental Mode: axisData";
set xlabel "z [cm]"; set ylabel "E_{/Symbol \174\174} [MV/m]";
plot file1 using (1e-1*$1):(1e-6*$2) notitle with lines ls 1;

if (term_type == 0) pause mouse "click on graph to cont.\n";

if (term_type == 1) set output "cavity_2.ps"
if (term_type == 2) set output "cavity_2.png"
if (term_type == 3) set output "cavity_2.jpg"

set multiplot;

set size 0.5, 0.5; set origin 0.0, 0.5;
set title "Cavity Mode: EDipole";
set xlabel "z [cm]"; set ylabel "E_{/Symbol \\136} [MV]";
plot file2 using (1e-1*$1):(1e-6*$2) notitle with lines ls 3;

set origin 0.5, 0.5;
set title "Cavity Mode: EQuad";
set xlabel "z [cm]"; set ylabel "E_{/Symbol \\136} [MV/m]";
plot file5 using (1e-1*$1):(1e-6*$2) notitle with lines ls 3;

set origin 0.0, 0.0;
set title "Cavity: EFocus1 & EFocus2";
set xlabel "z [cm]"; set ylabel "E_{/Symbol \\136} [MV/m]";
plot file3 using (1e-1*$1):(1e-6*$2) notitle with lines ls 3, \
     file4 using (1e-1*$1):(1e-6*$2) notitle with lines ls 3;

unset multiplot;
if (term_type == 0) pause mouse "click on graph to cont.\n";

if (term_type == 1) set output "cavity_3.ps"
if (term_type == 2) set output "cavity_3.png"
if (term_type == 3) set output "cavity_3.jpg"

set multiplot;

set size 0.5, 0.5; set origin 0.0, 0.5;
set title "Cavity Mode: HDipole";
set xlabel "z [cm]"; set ylabel "H_{/Symbol \\136} [kA]";
plot file6 using (1e-1*$1):(1e-3*$2) notitle with lines ls 3;

set origin 0.5, 0.5;
set title "Cavity Mode: HMono";
set xlabel "z [cm]"; set ylabel "H_{/Symbol \\136} [kA/m]";
plot file7 using (1e-1*$1):(1e-3*$2) notitle with lines ls 3;

set origin 0.0, 0.0;
set title "Cavity Mode: HQuad";
set xlabel "z [cm]"; set ylabel "H_{/Symbol \\136} [kA/m]";
plot file8 using (1e-1*$1):(1e-3*$2) notitle with lines ls 3;

unset multiplot;
if (term_type == 0) pause mouse "click on graph to cont.\n";

if (term_type == 1) set output "cavity_4.ps"
if (term_type == 2) set output "cavity_4.png"
if (term_type == 3) set output "cavity_4.jpg"

set size 1.0, 1.0; set origin 0.0, 0.0;
set title "Cavity Thin Lens Model: {/Symbol \\362}Eds,  {/Symbol \\362}Hds";
set xlabel "z [cm]";
set ylabel "[MV, MV/m, MA, MA/m]";
set yrange [-0.01:];
plot file9 using (1e-1*($1+$4/2.0)):6:(1e-1*$4) notitle with boxes ls 3;
if (term_type == 0) pause mouse "click on graph to cont.\n";


Cosmetic vd UT fix

Cosmetic vd UT fix

:- begin_tests(vd).

:- use_module(u(v)).
:- use_module(u(vd)).
:- use_module(u(internal/db_i)).
:- use_module(u(util/lambda)).

test(clear_test_db, [fail, setup(db_clear(people))]) :-

	db_recorded(people, _).

test(db_copy, [setup(model_db), N =:= 3]) :-

   db_copy(people, people2),
   findall('.', db_recorded(people2, _), L),
   length(L, N).

test(db_erase, [setup(model_db)]) :-

   (  named_args_unify(people, _,
                       [weight, surname], [73, _], X),
      db_erase(X),
      fail ; true
   ),

   findall(Y,
           db_recorded(people, Y),
           LY),
   assertion(LY = [man_v(_, _, _, _, 'Eva', woman, _, _)]).

test(db_iterate1, [setup(model_db), N =:= 3]) :-

   findall('.', db_iterate(people, true, _), L),
   length(L, N).

test(db_iterate2, [setup(model_db), N =:= 2]) :-

   findall(O, db_iterate(people, sex(man), O), L),
   length(L, N).

test(db_iterate3, [setup(model_db), fail]) :-

   db_iterate(people, unexisting_name(man_v), _).

test(db_iterate4, [setup(model_db), N =:= 2]) :-

   findall(O, db_iterate(people, functor(man_v), O), L),
   length(L, N).

test(db_iterate4, [setup(model_db), N =:= 3]) :-

   findall(O, db_iterate(people, functor(_), O), L),
   length(L, N).

test(db_to_list, [setup(model_db)]) :-

   db_to_list(people, man_v, L1),
   length(L1, N1),
   assertion(N1 =:= 2),

   db_to_list(people, citizen_v, L2),
   length(L2, N2),
   assertion(N2 =:= 1),

   db_to_list(people, _, L3),
   length(L3, N3),
   assertion(N3 =:= 3).

test(db_put_object1, [setup(model_db)]) :-

   obj_construct(man_v, [name], ['Moses'], Man),
   db_put_object(people, Man).

test(db_put_object2, [setup(model_db)]) :-

   obj_construct(man_v, [name], ['Moses'], Man0),
   obj_rebase((object_v -> db_object_v), Man0, Man),
   db_put_object(people, Man).

test(db_put_object3, [setup(model_db)]) :-

   db_construct(people2, man_v, [name], ['Moses']),
   db_recorded(people2, Man), !,
   db_put_object(people2, Man).

test(db_put_objects,
    [setup(db_clear(people)),
     DB_Size =:= 3]
    ) :-

	maplist(obj_construct(man_v, [name]),
		[['Valera'], ['Vika'], ['Yura']],
		Men),

	db_put_objects(people,
		       Men+\El^member(El, Men),
		       fail),

	db_size(people, DB_Size).

test(db_recorded_bug1, [setup(model_db), N =:= 3]) :-

   findall('.', db_recorded(people, _), L),
   length(L, N).

test(db_recorded1,
     [setup(model_db),
      throws(error(no_object_field(X, db_ref), _))]) :-

   obj_construct(man_v, [sex], [man], X),
   db_recorded(people, X).

test(db_recorded2, [setup(model_db)]) :-

   findall('.',
           (obj_construct(man_v, [sex], [man], X0),
            obj_rebase((object_v -> db_object_v), X0, X),
            db_recorded(people, X)),
           L2),
   length(L2, N2),
   assertion(N2 =:= 1).

test(db_recorded3, [setup(model_db)]) :-

   findall('.',
           (obj_construct(man_v, [], [], X0),
            obj_rebase((object_v -> db_object_v), X0, X),
            db_recorded(people, X)),
           L2),
   length(L2, N2),
   assertion(N2 =:= 2).

test(db_recorded4, [setup(model_db)]) :-

   findall('.',
           (obj_construct(man_v, [height], [1.76], X0),
            obj_rebase((object_v -> db_object_v), X0, X),
            db_recorded(people, X)),
           L2),
   length(L2, N2),
   assertion(N2 =:= 2).

test(db_recorded5, [setup(db_clear(people))]) :-

   db_construct(people, man_v, [], []),
   db_recorded(people, X), !,
   db_recorded(people, X).

test(named_args_unify1, [setup(model_db)]) :-

   findall('.',
           named_args_unify(people, _, [sex], [man], _),
           ['.', '.']).

test(named_args_unify2, [setup(model_db)]) :-

   findall('.',
           named_args_unify(people, _, [sex, sex], [man, man], _),
           ['.', '.']).

test(named_args_unify_bug1, [setup(model_db)]) :-

   findall('.',
           named_args_unify(people, citizen_v, [sex], [man], _),
           ['.']).

test(named_args_unify_bug2, [setup(model_db)]) :-

   findall('.',
           named_args_unify(people, _, [], [], _),
           ['.', '.', '.']).

test(store_and_retrieve1,
    [setup(db_clear(people)),
     man(Sex, Name, Surname, Weight, Height) ==
     man(man, 'Adam', 'Adamov', 1, 3)]
    ) :-

	obj_construct(man_v,
		      [sex, name, surname, weight, height],
		      [man, 'Adam', 'Adamov', 1, 3],
		      Man),

	db_put_object(people, Man, Man1),

	assertion(obj_is_descendant(Man1, db_object_v)),
	assertion(\+ obj_is_descendant(Man1, man_v)),
	assertion(\+ obj_is_descendant(Man, db_object_v)),

	obj_field(Man1, sex, Sex),
	obj_field(Man1, name, Name),
	obj_field(Man1, surname, Surname),
	obj_field(Man1, weight, Weight),
	obj_field(Man1, height, Height).

test(key_rule1,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, man_v,
                [name, surname], ['Sergei', 'Lodyagin']),
   db_construct(people, man_v,
                [name, surname], ['Sergei', 'Lodyagin']).

test(key_rule2,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, man_v, [], []),
   db_construct(people, man_v, [], []).

test(key_rule3,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, man_v, [name], ['Sergei']),
   db_construct(people, man_v, [], []).

test(key_rule4,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, man_v, [], []),
   db_construct(people, man_v, [name], ['Sergei']).

test(key_rule5, [setup(db_clear(people))]) :-

   db_construct(people, man_v,
                [name, surname], ['Sergei', 'Lodyagin']),

   db_construct(people, man_v,
                [name, surname], ['Sergei', 'Sikorsky']).

test(key_rule6,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, man_v,
                [name], ['Sergei']),

   db_construct(people, man_v,
                [name], ['Sergei']).

test(key_rule7,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, man_v,
                [name], ['Sergei']),

   db_construct(people, man_v,
                [surname], ['Lodyagin']).

test(key_rule8, [setup(db_clear(people))]) :-

   db_construct(people, man_v,
                [name], ['Sergei']),

   db_construct(people, man_v,
                [name], ['Artem']).

test(key_rule9,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, man_v,
                [name, surname], ['Sergei', 'Sysoev']),

   db_construct(people, man_v,
                [name], ['Sergei']).

test(key_rule10,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, man_v,
                [name], ['Sergei']),

   db_construct(people, man_v,
                [name, surname], ['Sergei', 'Sysoev']).

test(key_rule11,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, citizen_v, [id], [4]),
   db_construct(people, citizen_v, [], []).

test(key_rule12, [setup(db_clear(people))]) :-

   db_construct(people, citizen_v, [id], [4]),
   db_construct(people, man_v, [], []).

test(key_rule13, [setup(db_clear(people))]) :-

   db_construct(people, citizen_v, [id], [4]),
   db_construct(people, man_v, [name], ['James']).

test(key_rule14,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, citizen_v, [id], [4]),
   db_construct(people, man_v, [], []),
   db_construct(people, citizen_v, [id], [5]).

test(key_rule15, [setup(db_clear(people))]) :-

   db_construct(people, citizen_v, [id], [4]),
   db_construct(people, man_v,
                [name, surname], ['James', 'Crick']),
   db_construct(people, citizen_v,
                [name, surname, id], ['Adam', 'Adamovitch', 5]).

test(key_rule16,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, man_v, [name], ['James']),
   db_construct(people, citizen_v, [id], [4]).

test(db_singleton_v1, [setup(db_clear(people))]) :-

   db_construct(people, man_v,
                [name, surname], ['Sergei', 'Lodyagin']),
   db_construct(people, db_singleton_v,
                [key_policy], [overwrite]),
   db_construct(people, man_v, [surname], ['Lodyagin']),

   true.

model_db :-

	db_clear(people),
	db_clear(people2),

        db_construct(people, man_v,
                     [sex, name, weight], [man, 'Adam', 73]),
        db_construct(people, man_v,
                     [sex, name, weight], [woman, 'Eva', 64]),

        db_construct(people, citizen_v,
                      [sex, name, surname, country],
                      [man, 'Vladimir', 'Mayakovsky',
                       ['Soviet Union']]).

:- end_tests(vd).

:- begin_tests(vd).

:- use_module(u(v)).
:- use_module(u(vd)).
:- use_module(u(internal/db_i)).
:- use_module(u(util/lambda)).

test(clear_test_db, [fail, setup(db_clear(people))]) :-

	db_recorded(people, _).

test(db_copy, [setup(model_db), N =:= 3]) :-

   db_copy(people, people2),
   findall('.', db_recorded(people2, _), L),
   length(L, N).

test(db_erase, [setup(model_db)]) :-

   (  named_args_unify(people, _,
                       [weight, surname], [73, _], X),
      db_erase(X),
      fail ; true
   ),

   findall(Y,
           db_recorded(people, Y),
           LY),
   assertion(LY = [man_v(_, _, _, 'Eva', woman, _, _)]).

test(db_iterate1, [setup(model_db), N =:= 3]) :-

   findall('.', db_iterate(people, true, _), L),
   length(L, N).

test(db_iterate2, [setup(model_db), N =:= 2]) :-

   findall(O, db_iterate(people, sex(man), O), L),
   length(L, N).

test(db_iterate3, [setup(model_db), fail]) :-

   db_iterate(people, unexisting_name(man_v), _).

test(db_iterate4, [setup(model_db), N =:= 2]) :-

   findall(O, db_iterate(people, functor(man_v), O), L),
   length(L, N).

test(db_iterate4, [setup(model_db), N =:= 3]) :-

   findall(O, db_iterate(people, functor(_), O), L),
   length(L, N).

test(db_to_list, [setup(model_db)]) :-

   db_to_list(people, man_v, L1),
   length(L1, N1),
   assertion(N1 =:= 2),

   db_to_list(people, citizen_v, L2),
   length(L2, N2),
   assertion(N2 =:= 1),

   db_to_list(people, _, L3),
   length(L3, N3),
   assertion(N3 =:= 3).

test(db_put_objects,
    [setup(db_clear(people)),
     DB_Size =:= 3]
    ) :-

	maplist(obj_construct(man_v, [name]),
		[['Valera'], ['Vika'], ['Yura']],
		Men),

	db_put_objects(people,
		       Men+\El^member(El, Men),
		       fail),

	db_size(people, DB_Size).

test(db_recorded_bug1, [setup(model_db), N =:= 3]) :-

   findall('.', db_recorded(people, _), L),
   length(L, N).

test(db_recorded1,
     [setup(model_db),
      throws(error(no_object_field(X, db_ref), _))]) :-

   obj_construct(man_v, [sex], [man], X),
   db_recorded(people, X).

test(db_recorded2, [setup(model_db)]) :-

   findall('.',
           (obj_construct(man_v, [sex], [man], X0),
            obj_rebase((object_v -> db_object_v), X0, X),
            db_recorded(people, X)),
           L2),
   length(L2, N2),
   assertion(N2 =:= 1).

test(db_recorded3, [setup(model_db)]) :-

   findall('.',
           (obj_construct(man_v, [], [], X0),
            obj_rebase((object_v -> db_object_v), X0, X),
            db_recorded(people, X)),
           L2),
   length(L2, N2),
   assertion(N2 =:= 2).

test(db_recorded4, [setup(model_db)]) :-

   findall('.',
           (obj_construct(man_v, [height], [1.76], X0),
            obj_rebase((object_v -> db_object_v), X0, X),
            db_recorded(people, X)),
           L2),
   length(L2, N2),
   assertion(N2 =:= 2).

test(db_recorded5, [setup(db_clear(people))]) :-

   db_construct(people, man_v, [], []),
   db_recorded(people, X), !,
   db_recorded(people, X).

test(named_args_unify1, [setup(model_db)]) :-

   findall('.',
           named_args_unify(people, _, [sex], [man], _),
           ['.', '.']).

test(named_args_unify2, [setup(model_db)]) :-

   findall('.',
           named_args_unify(people, _, [sex, sex], [man, man], _),
           ['.', '.']).

test(named_args_unify_bug1, [setup(model_db)]) :-

   findall('.',
           named_args_unify(people, citizen_v, [sex], [man], _),
           ['.']).

test(named_args_unify_bug2, [setup(model_db)]) :-

   findall('.',
           named_args_unify(people, _, [], [], _),
           ['.', '.', '.']).

test(store_and_retrieve1,
    [setup(db_clear(people)),
     man(Sex, Name, Surname, Weight, Height) ==
     man(man, 'Adam', 'Adamov', 1, 3)]
    ) :-

	obj_construct(man_v,
		      [sex, name, surname, weight, height],
		      [man, 'Adam', 'Adamov', 1, 3],
		      Man),

	db_put_object(people, Man, Man1),

	assertion(obj_is_descendant(Man1, db_object_v)),
	assertion(\+ obj_is_descendant(Man1, man_v)),
	assertion(\+ obj_is_descendant(Man, db_object_v)),

	obj_field(Man1, sex, Sex),
	obj_field(Man1, name, Name),
	obj_field(Man1, surname, Surname),
	obj_field(Man1, weight, Weight),
	obj_field(Man1, height, Height).

test(key_rule1,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, man_v,
                [name, surname], ['Sergei', 'Lodyagin']),
   db_construct(people, man_v,
                [name, surname], ['Sergei', 'Lodyagin']).

test(key_rule2,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, man_v, [], []),
   db_construct(people, man_v, [], []).

test(key_rule3,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, man_v, [name], ['Sergei']),
   db_construct(people, man_v, [], []).

test(key_rule4,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, man_v, [], []),
   db_construct(people, man_v, [name], ['Sergei']).

test(key_rule5, [setup(db_clear(people))]) :-

   db_construct(people, man_v,
                [name, surname], ['Sergei', 'Lodyagin']),

   db_construct(people, man_v,
                [name, surname], ['Sergei', 'Sikorsky']).

test(key_rule6,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, man_v,
                [name], ['Sergei']),

   db_construct(people, man_v,
                [name], ['Sergei']).

test(key_rule7,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, man_v,
                [name], ['Sergei']),

   db_construct(people, man_v,
                [surname], ['Lodyagin']).

test(key_rule8, [setup(db_clear(people))]) :-

   db_construct(people, man_v,
                [name], ['Sergei']),

   db_construct(people, man_v,
                [name], ['Artem']).

test(key_rule9,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, man_v,
                [name, surname], ['Sergei', 'Sysoev']),

   db_construct(people, man_v,
                [name], ['Sergei']).

test(key_rule10,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, man_v,
                [name], ['Sergei']),

   db_construct(people, man_v,
                [name, surname], ['Sergei', 'Sysoev']).

test(key_rule11,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, citizen_v, [id], [4]),
   db_construct(people, citizen_v, [], []).

test(key_rule12, [setup(db_clear(people))]) :-

   db_construct(people, citizen_v, [id], [4]),
   db_construct(people, man_v, [], []).

test(key_rule13, [setup(db_clear(people))]) :-

   db_construct(people, citizen_v, [id], [4]),
   db_construct(people, man_v, [name], ['James']).

test(key_rule14,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, citizen_v, [id], [4]),
   db_construct(people, man_v, [], []),
   db_construct(people, citizen_v, [id], [5]).

test(key_rule15, [setup(db_clear(people))]) :-

   db_construct(people, citizen_v, [id], [4]),
   db_construct(people, man_v,
                [name, surname], ['James', 'Crick']),
   db_construct(people, citizen_v,
                [name, surname, id], ['Adam', 'Adamovitch', 5]).

test(key_rule16,
     [setup(db_clear(people)),
      error(db_key_exists(people, _, _))]) :-

   db_construct(people, man_v, [name], ['James']),
   db_construct(people, citizen_v, [id], [4]).

test(db_singleton_v1, [setup(db_clear(people))]) :-

   db_construct(people, man_v,
                [name, surname], ['Sergei', 'Lodyagin']),
   db_construct(people, db_singleton_v,
                [key_policy], [overwrite]),
   db_construct(people, man_v, [surname], ['Lodyagin']),

   true.

model_db :-

	db_clear(people),
	db_clear(people2),

        db_construct(people, man_v,
                     [sex, name, weight], [man, 'Adam', 73]),
        db_construct(people, man_v,
                     [sex, name, weight], [woman, 'Eva', 64]),

        db_construct(people, citizen_v,
                      [sex, name, surname, country],
                      [man, 'Vladimir', 'Mayakovsky',
                       ['Soviet Union']]).

:- end_tests(vd).


minor tweaks to ranger config

minor tweaks to ranger config

import os

PROTEUS_INCLUDE_DIR = os.getenv('PROTEUS_PREFIX')+'/include'
PROTEUS_LIB_DIR = os.getenv('PROTEUS_PREFIX')+'/lib'
PROTEUS_EXTRA_COMPILE_ARGS= ['-DF77_POST_UNDERSCORE','-DUSE_BLAS','-DCMRVEC_BOUNDS_CHECK','-DMV_VECTOR_BOUNDS_CHECK']
PROTEUS_EXTRA_LINK_ARGS=['-L'+os.getenv('TACC_MKL_LIB'),'-lmkl_lapack','-lmkl_intel_lp64','-lmkl_sequential','-lmkl_core','-lpthread']
PROTEUS_EXTRA_FC_COMPILE_ARGS= ['-Wall']
PROTEUS_EXTRA_FC_LINK_ARGS=['-L'+os.getenv('TACC_MKL_LIB'),'-lmkl_lapack','-lmkl_intel_lp64','-lmkl_sequential','-lmkl_core','-lpthread']

PROTEUS_SUPERLU_INCLUDE_DIR = PROTEUS_INCLUDE_DIR
PROTEUS_SUPERLU_H   = r'"slu_ddefs.h"'
PROTEUS_SUPERLU_LIB_DIR = PROTEUS_LIB_DIR
PROTEUS_SUPERLU_LIB = 'superlu'

PROTEUS_BLAS_INCLUDE_DIR   = '.'
PROTEUS_BLAS_H     = r'"proteus_blas.h"'
PROTEUS_BLAS_LIB_DIR = os.getenv('TACC_MKL_LIB')
PROTEUS_BLAS_LIB   = 'f77blas'

PROTEUS_LAPACK_INCLUDE_DIR = '.'
PROTEUS_LAPACK_H   = r'"proteus_lapack.h"'
PROTEUS_LAPACK_LIB_DIR = os.getenv('TACC_MKL_LIB')
PROTEUS_LAPACK_LIB = 'mkl_lapack'
PROTEUS_LAPACK_INTEGER = 'int'

PROTEUS_MPI_INCLUDE_DIR = '.'
PROTEUS_MPI_LIB_DIR = 'mkl_lapack'
PROTEUS_MPI_LIBS = []

PROTEUS_TRIANGLE_INCLUDE_DIR = PROTEUS_INCLUDE_DIR
PROTEUS_TRIANGLE_H = r'"triangle.h"'
PROTEUS_TRIANGLE_LIB_DIR = PROTEUS_LIB_DIR
PROTEUS_TRIANGLE_LIB ='tri'

PROTEUS_DAETK_INCLUDE_DIR = [PROTEUS_INCLUDE_DIR]
PROTEUS_DAETK_LIB_DIR = PROTEUS_LIB_DIR
PROTEUS_DAETK_LIB ='daetk'
PROTEUS_PETSC_LIB_DIRS = []
PROTEUS_PETSC_LIBS = []
PROTEUS_PETSC_INCLUDE_DIRS = []

import os

PROTEUS_INCLUDE_DIR = os.getenv('PROTEUS_PREFIX')+'/include'
PROTEUS_LIB_DIR = os.getenv('PROTEUS_PREFIX')+'/lib'
PROTEUS_EXTRA_COMPILE_ARGS= ['-DF77_POST_UNDERSCORE','-DUSE_BLAS','-DCMRVEC_BOUNDS_CHECK','-DMV_VECTOR_BOUNDS_CHECK']
PROTEUS_EXTRA_LINK_ARGS=['-L'+os.getenv('TACC_ATLAS_LIB'),'-lcblas','-latlas','-lgcc_s']
PROTEUS_EXTRA_FC_COMPILE_ARGS= ['-Wall']
PROTEUS_EXTRA_FC_LINK_ARGS=['-L'+os.getenv('TACC_ATLAS_LIB'),'-lcblas','-latlas','-lgcc_s']

PROTEUS_SUPERLU_INCLUDE_DIR = PROTEUS_INCLUDE_DIR
PROTEUS_SUPERLU_H   = r'"slu_ddefs.h"'
PROTEUS_SUPERLU_LIB_DIR = PROTEUS_LIB_DIR
PROTEUS_SUPERLU_LIB = 'superlu'

PROTEUS_BLAS_INCLUDE_DIR   = '.'
PROTEUS_BLAS_H     = r'"proteus_blas.h"'
PROTEUS_BLAS_LIB_DIR = os.getenv('TACC_ATLAS_LIB')
PROTEUS_BLAS_LIB   = 'f77blas'

PROTEUS_LAPACK_INCLUDE_DIR = '.'
PROTEUS_LAPACK_H   = r'"proteus_lapack.h"'
PROTEUS_LAPACK_LIB_DIR = os.getenv('TACC_ATLAS_LIB')
PROTEUS_LAPACK_LIB = 'lapack'
PROTEUS_LAPACK_INTEGER = 'int'

PROTEUS_MPI_INCLUDE_DIR = '.'
PROTEUS_MPI_LIB_DIR = '.'
PROTEUS_MPI_LIBS = []

PROTEUS_TRIANGLE_INCLUDE_DIR = PROTEUS_INCLUDE_DIR
PROTEUS_TRIANGLE_H = r'"triangle.h"'
PROTEUS_TRIANGLE_LIB_DIR = PROTEUS_LIB_DIR
PROTEUS_TRIANGLE_LIB ='tri'

PROTEUS_DAETK_INCLUDE_DIR = [PROTEUS_INCLUDE_DIR]
PROTEUS_DAETK_LIB_DIR = PROTEUS_LIB_DIR
PROTEUS_DAETK_LIB ='daetk'


Fix UTs (v)

Fix UTs (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) :-
   % test class_create/3 version

   current_prolog_flag(verbose, Old_Verbose),
   set_prolog_flag(verbose, silent),
   reload_all_classes,
   set_prolog_flag(verbose, Old_Verbose),

   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) :-
   % test class_create/4 version

   current_prolog_flag(verbose, Old_Verbose),
   set_prolog_flag(verbose, silent),
   reload_all_classes,
   set_prolog_flag(verbose, Old_Verbose),

   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))]
     ) :-

   current_prolog_flag(verbose, Old_Verbose),
   set_prolog_flag(verbose, silent),
   reload_all_classes,
   set_prolog_flag(verbose, Old_Verbose),

   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) :-
   % It is a strange feature

   current_prolog_flag(verbose, Old_Verbose),
   set_prolog_flag(verbose, silent),
   reload_all_classes,
   set_prolog_flag(verbose, Old_Verbose),

   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_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(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_parent2,
     [L == [callup_v, class_create_test_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(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(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).

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_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_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]).

% 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(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).

test(eval_fields1) :-

   % 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_fields2,
     [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).

:- 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) :-
   % test class_create/3 version

   current_prolog_flag(verbose, Old_Verbose),
   set_prolog_flag(verbose, silent),
   reload_all_classes,
   set_prolog_flag(verbose, Old_Verbose),

   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) :-
   % test class_create/4 version

   current_prolog_flag(verbose, Old_Verbose),
   set_prolog_flag(verbose, silent),
   reload_all_classes,
   set_prolog_flag(verbose, Old_Verbose),

   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))]
     ) :-

   current_prolog_flag(verbose, Old_Verbose),
   set_prolog_flag(verbose, silent),
   reload_all_classes,
   set_prolog_flag(verbose, Old_Verbose),

   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) :-
   % It is a strange feature

   current_prolog_flag(verbose, Old_Verbose),
   set_prolog_flag(verbose, silent),
   reload_all_classes,
   set_prolog_flag(verbose, Old_Verbose),

   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_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(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_parent2,
     [L == [callup_v, class_create_test_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(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_multiheader_v, [], [], MH),
   MH/bodies ^= [a, H1/body],
   assertion(MH/bodies =^= [a, body]).

test(eval_obj_expr6_compound) :-

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

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).

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_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_multiheader_v), H1, H2),
   obj_parents(H2, P2),
   assertion(P2 == [http_multiheader_v, http_header_v, object_v,
                    object_base_v]).

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]).

% 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(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).

test(eval_fields1) :-

   % 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_fields2,
     [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).

:- end_tests(v).


Cosmetic

Cosmetic

:- begin_tests(randgen).
:- use_module(randgen).
:- use_module(library(clpfd)).

test(fd_random1_gnu) :-

   X in 5..15,
   fd_random(lcq, gnu, 0, S1, X),
   fd_random(lcq, gnu, 0, S1, X),
   assertion(S1 == 12345),
   assertion(X == 8).

test(fd_random1_knuth) :-

   X in 5..15,
   fd_random(lcq, knuth, 0, S1, X),
   fd_random(lcq, knuth, 0, S1, X),
   assertion(S1 == 1442695040888963407),
   assertion(X == 12).

:- end_tests(randgen).

:- begin_tests(randgen).
:- use_module(randgen).

test(fd_random1_gnu) :-

   X in 5..15,
   fd_random(lcq, gnu, 0, S1, X),
   fd_random(lcq, gnu, 0, S1, X),
   assertion(S1 == 12345),
   assertion(X == 8).

test(fd_random1_knuth) :-

   X in 5..15,
   fd_random(lcq, knuth, 0, S1, X),
   fd_random(lcq, knuth, 0, S1, X),
   assertion(S1 == 1442695040888963407),
   assertion(X == 12).

:- end_tests(randgen).


kdev: enable kernel knobs

kdev: enable kernel knobs

#!/bin/bash
#Don't fiddle with users .config if there is one already
if [ -f ./linux/.config ]; then
	echo "Using existing kernel config"
else
	make -C ./linux x86_64_defconfig
	sed -i '/^CONFIG_VIRTIO=/{h;s/=.*/=CONFIG_VIRTIO=m/};${x;/^$/{s//CONFIG_VIRTIO=m/;H};x}' ./linux/.config
	sed -i '/^CONFIG_VIRTIO_NET=/{h;s/=.*/=CONFIG_VIRTIO_NET=m/};${x;/^$/{s//CONFIG_VIRTIO_NET=m/;H};x}' ./linux/.config
	sed -i '/^CONFIG_VIRTIO_PCI=/{h;s/=.*/=CONFIG_VIRTIO_PCI=m/};${x;/^$/{s//CONFIG_VIRTIO_PCI=m/;H};x}' ./linux/.config
	sed -i '/^CONFIG_BRIDGE=/{h;s/=.*/=CONFIG_BRIDGE=m/};${x;/^$/{s//CONFIG_BRIDGE=m/;H};x}' ./linux/.config
	sed -i '/^CONFIG_CIFS=/{h;s/=.*/=CONFIG_CIFS=m/};${x;/^$/{s//CONFIG_CIFS=m/;H};x}' ./linux/.config
	sed -i '/^CONFIG_VETH=/{h;s/=.*/=CONFIG_VETH=m/};${x;/^$/{s//CONFIG_VETH=m/;H};x}' ./linux/.config
	sed -i '/^CONFIG_TIPC=/{h;s/=.*/=CONFIG_TIPC=m/};${x;/^$/{s//CONFIG_TIPC=m/;H};x}' ./linux/.config
	sed -i '/^CONFIG_TIPC_MEDIA_UDP=/{h;s/=.*/=CONFIG_TIPC_MEDIA_UDP=y/};${x;/^$/{s//CONFIG_TIPC_MEDIA_UDP=y/;H};x}' ./linux/.config

fi

#!/bin/bash
#Don't fiddle with users .config if there is one already
if [ -f ./linux/.config ]; then
	echo "Using existing kernel config"
else
	make -C ./linux x86_64_defconfig
	sed -i '/^CONFIG_VIRTIO=/{h;s/=.*/=CONFIG_VIRTIO=m/};${x;/^$/{s//CONFIG_VIRTIO=m/;H};x}' ./linux/.config
	sed -i '/^CONFIG_VIRTIO_NET=/{h;s/=.*/=CONFIG_VIRTIO_NET=m/};${x;/^$/{s//CONFIG_VIRTIO_NET=m/;H};x}' ./linux/.config
	sed -i '/^CONFIG_VIRTIO_PCI=/{h;s/=.*/=CONFIG_VIRTIO_PCI=m/};${x;/^$/{s//CONFIG_VIRTIO_PCI=m/;H};x}' ./linux/.config
fi


legend below

legend below

set terminal png medium size 800, 500
set output "linux-statistics.png"

set style data lines
set y2tics
set grid x y
set border

set xdata time
set format x "%Y-%m"
set timefmt "%Y-%m-%d"
set xtics "2005-06", 31536000

set ylabel "MB"
set y2label "number of files"

set key below Right reverse box
plot 'linux-statistics.txt' using 1:3 t 'size', \
     'linux-statistics.txt' using 1:4 t 'files' axes x1y2

set terminal png medium size 800, 500
set output "linux-statistics.png"

set style data lines
set y2tics
set grid x y
set border

set xdata time
set format x "%Y-%m"
set timefmt "%Y-%m-%d"
set xtics "2005-06", 31536000

set ylabel "MB"
set y2label "number of files"

plot 'linux-statistics.txt' using 1:3 t 'size', \
     'linux-statistics.txt' using 1:4 t 'files' axes x1y2


gnuplot basic graph

gnuplot basic graph

set datafile separator ","
set terminal png size 900,400
set ylabel "kwh"
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set format x "%Y-%m-%d %H"
set xtics rotate by 90 offset 0,-7 out nomirror
set bmargin at screen 0.30
set key left top
set grid

filename="store/all.csv"
plot filename using 1:3 title 'power (kwh)' with boxes
set title "Power usage (kwh) by half hour over time"

set datafile separator ","
set terminal png size 900,400
set ylabel "kwh"
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set format x "%Y-%m-%d %H"
set xtics rotate by 90 offset 0,-7 out nomirror
set bmargin at screen 0.30
set key left top
set grid

filename="store1/all.csv"
plot filename using 1:3 title 'power (kwh)' with boxes
set title "Power usage (kwh) by half hour over time"


strip a bit more to not misinterprete empty string with embedded whitespace as true

git-svn-id: 4e7379b20b57f8e3dde5a0b7363f233184647162@2363 4e380d45-d1fd-0310-85a7-d18ec86df0ad

############################################################################
#  Makefile.subdir.gnu
#
#  Part of the STXXL. See http://stxxl.sourceforge.net
#
#  Copyright (C) 2007 Andreas Beckmann <beckmann@mpi-inf.mpg.de>
#
#  Distributed under the Boost Software License, Version 1.0.
#  (See accompanying file LICENSE_1_0.txt or copy at
#  http://www.boost.org/LICENSE_1_0.txt)
############################################################################

include $(TOPDIR)/make.settings

TEST_BINARIES		 = $(TESTS) $(TESTS-yes) $(TESTS-yesyes)
SKIPPED_TEST_BINARIES	 = $(TESTS-) $(TESTS-no) $(TESTS-yesno) $(TESTS-noyes) $(TESTS-nono)

tests: $(TEST_BINARIES:%=%.$(bin))

lib: $(LIB_SRC:.cpp=.$(lo))

clean::
	$(RM) *.$(lo) *.$o
	$(RM) *.$(lo:.o=).d *.$(o:.o=).d *.dT
	$(RM) $(TEST_BINARIES:=.$(bin))
	$(RM) $(SKIPPED_TEST_BINARIES:=.$(bin))

-include *.d

# Work around compiler bugs:
compiler_version	:= $(shell $(COMPILER) -v 2>&1 | tr ' ' '_')
bitness			:= $(shell file ../common/version.$(lo) 2>/dev/null)
#debug_override_opt	?= $(warning "DBGOO: $1")
debug_override_opt	?=
# usage: e.g. $(call needs_override,gcc_version_4.2,32-bit,3,[-g|any|none])
needs_override		?= $(call debug_override_opt,$1%$(compiler_version);$2%$(bitness);$3%$(OPT_LEVEL);$4%$(DEBUG))\
			   $(and $(findstring $1,$(compiler_version)),\
				$(or $(filter any,$2),$(filter $2,$(bitness))),\
				$(filter $3,$(OPT_LEVEL)),\
				$(or $(filter any,$4),$(if $(filter none,$4),$(if $(DEBUG),,empty)),$(filter $4,$(DEBUG))))
# usage: $(call apply_override yes|$(EMPTY),to,target)
apply_override		?= $(call debug_override_opt,enable=$1;to=$2;target=$3)\
			   $(if $(strip $1),$3: OPT_LEVEL=$2,)
# usage: $(call reduce_optimization,from,to,target,compiler,bits,debug[,type])
reduce_optimization	?= $(call apply_override,$(call needs_override,$4,$5,$1,$6),$2,$3.$($(or $(strip $7),bin)))

.SECONDARY:

.PHONY: tests lib clean

############################################################################
#  Makefile.subdir.gnu
#
#  Part of the STXXL. See http://stxxl.sourceforge.net
#
#  Copyright (C) 2007 Andreas Beckmann <beckmann@mpi-inf.mpg.de>
#
#  Distributed under the Boost Software License, Version 1.0.
#  (See accompanying file LICENSE_1_0.txt or copy at
#  http://www.boost.org/LICENSE_1_0.txt)
############################################################################

include $(TOPDIR)/make.settings

TEST_BINARIES		 = $(TESTS) $(TESTS-yes) $(TESTS-yesyes)
SKIPPED_TEST_BINARIES	 = $(TESTS-) $(TESTS-no) $(TESTS-yesno) $(TESTS-noyes) $(TESTS-nono)

tests: $(TEST_BINARIES:%=%.$(bin))

lib: $(LIB_SRC:.cpp=.$(lo))

clean::
	$(RM) *.$(lo) *.$o
	$(RM) *.$(lo:.o=).d *.$(o:.o=).d *.dT
	$(RM) $(TEST_BINARIES:=.$(bin))
	$(RM) $(SKIPPED_TEST_BINARIES:=.$(bin))

-include *.d

# Work around compiler bugs:
compiler_version	:= $(shell $(COMPILER) -v 2>&1 | tr ' ' '_')
bitness			:= $(shell file ../common/version.$(lo) 2>/dev/null)
#debug_override_opt	?= $(warning "DBGOO: $1")
debug_override_opt	?=
# usage: e.g. $(call needs_override,gcc_version_4.2,32-bit,3,[-g|any|none])
needs_override		?= $(call debug_override_opt,$1%$(compiler_version);$2%$(bitness);$3%$(OPT_LEVEL);$4%$(DEBUG))\
			   $(and $(findstring $1,$(compiler_version)),\
				$(or $(filter any,$2),$(filter $2,$(bitness))),\
				$(filter $3,$(OPT_LEVEL)),\
				$(or $(filter any,$4),$(if $(filter none,$4),$(if $(DEBUG),,empty)),$(filter $4,$(DEBUG))))
# usage: $(call apply_override yes|$(EMPTY),to,target)
apply_override		?= $(call debug_override_opt,enable=$1;to=$2;target=$3)\
			   $(if $1,$3: OPT_LEVEL=$2,)
# usage: $(call reduce_optimization,from,to,target,compiler,bits,debug[,type])
reduce_optimization	?= $(call apply_override,$(call needs_override,$4,$5,$1,$6),$2,$3.$($(or $(strip $7),bin)))

.SECONDARY:

.PHONY: tests lib clean