From fc83b348a5a0eb70a784ee34efd570364550cbfd Mon Sep 17 00:00:00 2001
From: someone <jan@jvales.net>
Date: Mon, 4 Jun 2012 11:43:30 +0200
Subject: [PATCH] w and f tests and f component.

---
 abnormal.hyp                           |  22 +++++++++++++++++++++
 chk.sh                                 |  26 +++++++++++++++++++++++++
 component.tester.dl                    |   6 ++++++
 connect.tester.dl                      |   6 ++++++
 dlv.x86-64-linux-elf-static.bin => dlv | Bin
 f.dl                                   |   6 ++++++
 f.test1.dl                             |  19 ++++++++++++++++++
 f.test2.dl                             |  19 ++++++++++++++++++
 f.test3.dl                             |  19 ++++++++++++++++++
 f.test4.dl                             |  19 ++++++++++++++++++
 f.test5.dl                             |  19 ++++++++++++++++++
 test.sh                                |  25 ++++++++++++++++++++++++
 test_fault                             |  20 +++++++++++++++++++
 testconnect.sh                         |  14 +++++++++++++
 w.test1.dl                             |  23 ++++++++++++++++++++++
 w.test2.dl                             |  23 ++++++++++++++++++++++
 w.test3.dl                             |  23 ++++++++++++++++++++++
 w.test4.dl                             |  22 +++++++++++++++++++++
 w.test5.dl                             |  23 ++++++++++++++++++++++
 19 files changed, 334 insertions(+)
 create mode 100644 abnormal.hyp
 create mode 100755 chk.sh
 create mode 100644 component.tester.dl
 create mode 100644 connect.tester.dl
 rename dlv.x86-64-linux-elf-static.bin => dlv (100%)
 create mode 100755 test.sh
 create mode 100644 test_fault
 create mode 100755 testconnect.sh

diff --git a/abnormal.hyp b/abnormal.hyp
new file mode 100644
index 0000000..3b6e0c5
--- /dev/null
+++ b/abnormal.hyp
@@ -0,0 +1,22 @@
+ab(c).
+ab(psh).
+ab(w).
+ab(f).
+ab(s).
+ab(control_lcur_ci1).
+ab(control_ldemand_ci2).
+ab(control_sstorage_ci3).
+ab(control_swind_ci4).
+ab(control_sstorage_pshis).
+ab(control_swind_wiw).
+ab(control_co1_pshi1).
+ab(control_co2_wi1).
+ab(control_co3_fi1).
+ab(control_co4_si4).
+ab(control_co5_si5).
+ab(power_pin_si6).
+ab(power_pout_so2).
+ab(power_pshop_si1).
+ab(power_wop_si2).
+ab(power_fop_si3).
+ab(power_so1_pshi2).
diff --git a/chk.sh b/chk.sh
new file mode 100755
index 0000000..bec7de0
--- /dev/null
+++ b/chk.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+if [[ "$1" == "" ]]; then
+	COMPONENTS="c psh w f s"
+else
+	COMPONENTS="$1"
+fi
+
+if [[ "$2" == "" ]]; then
+	TESTS="1 2 3 4 5"
+else
+	TESTS="$2"
+fi
+
+for component in $(echo ${COMPONENTS})
+do
+	for test in $(echo ${TESTS})
+	do
+		ret=`./dlv -silent ${component}.dl ${component}.test${test}.dl component.tester.dl -N=80 | egrep "UNCOMPUTED|UNEXPECTED|DUPLICATED"`
+		if [[ $? != 1 ]]; then
+			echo "Component ${component} failed at test ${test}:"
+			echo ${ret}
+		fi
+	done
+done
+
diff --git a/component.tester.dl b/component.tester.dl
new file mode 100644
index 0000000..7566271
--- /dev/null
+++ b/component.tester.dl
@@ -0,0 +1,6 @@
+UNCOMPUTED_c(C,O,X) :- expect_c(C,O,X), not c(C,O,X).
+UNCOMPUTED_p(C,O,X) :- expect_p(C,O,X), not p(C,O,X).
+UNEXPECTED_c(C,O,X) :- c(C,O,X), not expect_c(C,O,X).
+UNEXPECTED_p(C,O,X) :- p(C,O,X), not expect_p(C,O,X).
+DUPLICATED_c(C,O,X,Y) :- c(C,O,X), c(C,O,Y), X < Y.
+DUPLICATED_p(C,O,X,Y) :- p(C,O,X), p(C,O,Y), X < Y.
diff --git a/connect.tester.dl b/connect.tester.dl
new file mode 100644
index 0000000..bcb87a4
--- /dev/null
+++ b/connect.tester.dl
@@ -0,0 +1,6 @@
+UNCOMPUTED_c(O,X) :- expect_out_c(O,X), not out_c(O,X).
+UNCOMPUTED_p(O,X) :- expect_out_p(O,X), not out_p(O,X).
+UNEXPECTED_c(O,X) :- out_c(O,X), not expect_out_c(O,X).
+UNEXPECTED_p(O,X) :- out_p(O,X), not expect_out_p(O,X).
+DUPLICATED_c(O,X,Y) :- out_c(O,X), out_c(O,Y), X < Y.
+DUPLICATED_p(O,X,Y) :- out_p(O,X), out_p(O,Y), X < Y.
diff --git a/dlv.x86-64-linux-elf-static.bin b/dlv
similarity index 100%
rename from dlv.x86-64-linux-elf-static.bin
rename to dlv
diff --git a/f.dl b/f.dl
index e69de29..50e4aae 100644
--- a/f.dl
+++ b/f.dl
@@ -0,0 +1,6 @@
+
+p(C,op,OP) :- not ab(C), caloric_plant(C), c(C,i1,0), OP = 0.
+p(C,op,OP) :- not ab(C), caloric_plant(C), c(C,i1,I1), c_max(C,MAX), I1 > 0, MAX >= I1, OP = I1, #int(OP).
+p(C,op,OP) :- not ab(C), caloric_plant(C), c(C,i1,I1), c_max(C,MAX), I1 > MAX, OP = MAX, #int(OP).
+
+
diff --git a/f.test1.dl b/f.test1.dl
index e69de29..4187d2c 100644
--- a/f.test1.dl
+++ b/f.test1.dl
@@ -0,0 +1,19 @@
+% define a caloric plant
+
+% f is our fossil plant
+caloric_plant(f).
+
+% can produce 60 KW max.
+c_max(f,60).
+
+% define control i1 to 5KW (we request 5 KW)
+c(f,i1,5).
+
+% we test.
+% expecting i1 to be 5
+expect_c(f,i1,5).
+
+% and therefore we shall produce 5KW
+expect_p(f,op,5).
+
+
diff --git a/f.test2.dl b/f.test2.dl
index e69de29..32ce978 100644
--- a/f.test2.dl
+++ b/f.test2.dl
@@ -0,0 +1,19 @@
+% define a caloric plant
+
+% f is our fossil plant
+caloric_plant(f).
+
+% can produce 60 KW max.
+c_max(f,60).
+
+% define control i1 to 0KW (we request 0 KW)
+c(f,i1,0).
+
+% we test.
+% expecting i1 to be 0
+expect_c(f,i1,0).
+
+% and therefore we shall produce 0KW
+expect_p(f,op,0).
+
+
diff --git a/f.test3.dl b/f.test3.dl
index e69de29..b7072a9 100644
--- a/f.test3.dl
+++ b/f.test3.dl
@@ -0,0 +1,19 @@
+% define a caloric plant
+
+% f is our fossil plant
+caloric_plant(f).
+
+% can produce 60 KW max.
+c_max(f,60).
+
+% define control i1 to 60KW (we request 60 KW)
+c(f,i1,60).
+
+% we test.
+% expecting i1 to be 60
+expect_c(f,i1,60).
+
+% and therefore we shall produce 60KW
+expect_p(f,op,60).
+
+
diff --git a/f.test4.dl b/f.test4.dl
index e69de29..649d0bb 100644
--- a/f.test4.dl
+++ b/f.test4.dl
@@ -0,0 +1,19 @@
+% define a caloric plant
+
+% f is our fossil plant
+caloric_plant(f).
+
+% can produce 60 KW max.
+c_max(f,60).
+
+% define control i1 to 65KW (we request 65 KW)
+c(f,i1,65).
+
+% we test.
+% expecting i1 to be 65
+expect_c(f,i1,65).
+
+% and therefore we shall produce 60KW as 60 is our MAX
+expect_p(f,op,60).
+
+
diff --git a/f.test5.dl b/f.test5.dl
index e69de29..070deb1 100644
--- a/f.test5.dl
+++ b/f.test5.dl
@@ -0,0 +1,19 @@
+% define a caloric plant
+
+% f is our fossil plant
+caloric_plant(f).
+
+% can produce 60 KW max.
+c_max(f,60).
+
+% define control i1 to 10KW (we request 10 KW)
+c(f,i1,10).
+
+% we test.
+% expecting i1 to be 10
+expect_c(f,i1,10).
+
+% and therefore we shall produce 10KW
+expect_p(f,op,10).
+
+
diff --git a/test.sh b/test.sh
new file mode 100755
index 0000000..ef3755a
--- /dev/null
+++ b/test.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+if [[ "$1" == "" ]]; then
+	COMPONENTS="c psh w f s"
+else
+	COMPONENTS="$1"
+fi
+
+if [[ "$2" == "" ]]; then
+	TESTS="1 2 3 4 5"
+else
+	TESTS="$2"
+fi
+
+for component in $(echo ${COMPONENTS})
+do
+	echo "Testing components ${component}:"
+	for test in $(echo ${TESTS})
+	do
+		echo "Running test ${test}:"
+		./dlv -silent ${component}.dl ${component}.test${test}.dl component.tester.dl -N=80
+	done
+	echo ""
+done
+
diff --git a/test_fault b/test_fault
new file mode 100644
index 0000000..f050444
--- /dev/null
+++ b/test_fault
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+if [[ "$1" == "" ]]; then
+	TESTS=`seq 10`
+else
+	TESTS="$1"
+fi
+
+if [[ $2 == "" ]]; then
+	DIAG="FRsingle"
+else
+	DIAG="$2"
+fi
+
+for test in $(echo ${TESTS})
+do
+	echo "Running test ${test}:"
+	./dlv -silent -${DIAG} c.dl psh.dl w.dl f.dl s.dl connect.dl abnormal.hyp connect.test${test}.dl -N=60
+	echo ""
+done
diff --git a/testconnect.sh b/testconnect.sh
new file mode 100755
index 0000000..a221903
--- /dev/null
+++ b/testconnect.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+if [[ "$1" == "" ]]; then
+	TESTS=`seq 10`
+else
+	TESTS="$1"
+fi
+
+echo "Testing connect:"
+for test in $(echo ${TESTS})
+do
+	echo "Running test ${test}:"
+	./dlv -silent c.dl psh.dl w.dl f.dl s.dl connect.dl connect.test${test}.dl connect.tester.dl -N=80
+done
diff --git a/w.test1.dl b/w.test1.dl
index e69de29..8cc2977 100644
--- a/w.test1.dl
+++ b/w.test1.dl
@@ -0,0 +1,23 @@
+% testing a wind-plant
+windmill(w).
+
+% define max capacity
+c_max(w,20).
+
+% define control i1 to 5KW (we request 5 KW)
+c(w,i1,5).
+
+% define control iw to 10 windspeed
+c(w,iw,10).
+
+% we test.
+% expecting i1 to be 5
+expect_c(f,i1,5).
+
+% expecting iw to be 10
+expect_c(f,iw,10).
+
+% and therefore we shall produce 10KW
+expect_p(f,op,5).
+
+
diff --git a/w.test2.dl b/w.test2.dl
index e69de29..fd51099 100644
--- a/w.test2.dl
+++ b/w.test2.dl
@@ -0,0 +1,23 @@
+% testing a wind-plant
+windmill(w).
+
+% define max capacity
+c_max(w,20).
+
+% define control i1 to 0KW (we request 0 KW)
+c(w,i1,0).
+
+% define control iw to 10 windspeed
+c(w,iw,10).
+
+% we test.
+% expecting i1 to be 0
+expect_c(f,i1,0).
+
+% expecting iw to be 10
+expect_c(f,iw,10).
+
+% and therefore we shall produce 0KW
+expect_p(f,op,0).
+
+
diff --git a/w.test3.dl b/w.test3.dl
index e69de29..d0b2e13 100644
--- a/w.test3.dl
+++ b/w.test3.dl
@@ -0,0 +1,23 @@
+% testing a wind-plant
+windmill(w).
+
+% define max capacity
+c_max(w,20).
+
+% define control i1 to 5KW (we request 5 KW)
+c(w,i1,5).
+
+% define control iw to 0 windspeed
+c(w,iw,0).
+
+% we test.
+% expecting i1 to be 5
+expect_c(f,i1,5).
+
+% expecting iw to be 0
+expect_c(f,iw,0).
+
+% and therefore we shall produce 10KW
+expect_p(f,op,0).
+
+
diff --git a/w.test4.dl b/w.test4.dl
index e69de29..320a53a 100644
--- a/w.test4.dl
+++ b/w.test4.dl
@@ -0,0 +1,22 @@
+% testing a wind-plant
+windmill(w).
+
+% define max capacity
+c_max(w,20).
+
+% define control i1 to 25KW (we request 25 KW)
+c(w,i1,25).
+
+% define control iw to 10 windspeed
+c(w,iw,10).
+
+% we test.
+% expecting i1 to be 25
+expect_c(f,i1,25).
+
+% expecting iw to be 10
+expect_c(f,iw,10).
+
+% and therefore we shall produce 20KW as (MAX is 20)
+expect_p(f,op,20).
+
diff --git a/w.test5.dl b/w.test5.dl
index e69de29..0bdadcc 100644
--- a/w.test5.dl
+++ b/w.test5.dl
@@ -0,0 +1,23 @@
+% testing a wind-plant
+windmill(w).
+
+% define max capacity
+c_max(w,20).
+
+% define control i1 to 5KW (we request 5 KW)
+c(w,i1,5).
+
+% define control iw to 50 windspeed
+c(w,iw,50).
+
+% we test.
+% expecting i1 to be 5
+expect_c(f,i1,5).
+
+% expecting iw to be 10
+expect_c(f,iw,50).
+
+% and therefore we shall produce 0KW
+expect_p(f,op,0).
+
+
-- 
2.43.0