From 0f3569445313057561a76d8ed61b0acf4f73d412 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Tue, 30 Sep 2014 16:24:19 -0400 Subject: [PATCH] contrib/opportunity: Added tests for opportunity Signed-off-by: Lucas Bajolet --- contrib/opportunity/tests/db_tests.nit | 99 ++++++++++++++++++++++++++++ contrib/opportunity/tests/sav/db_tests.res | 18 +++++ 2 files changed, 117 insertions(+) create mode 100644 contrib/opportunity/tests/db_tests.nit create mode 100644 contrib/opportunity/tests/sav/db_tests.res diff --git a/contrib/opportunity/tests/db_tests.nit b/contrib/opportunity/tests/db_tests.nit new file mode 100644 index 0000000..cbec6f7 --- /dev/null +++ b/contrib/opportunity/tests/db_tests.nit @@ -0,0 +1,99 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +# Tests for the model of Opportunity +module db_tests + +import opportunity_model + +redef class OpportunityDB + + fun wipe do + execute("DROP TABLE people;") + execute("DROP TABLE meetups;") + execute("DROP TABLE answers;") + execute("DROP TABLE part_answers;") + execute("DROP INDEX answers_clean;") + execute("DROP INDEX ans_clean;") + execute("DROP INDEX ppl_clean;") + end + +end + +print "Opening DB" + +var db = new OpportunityDB.open("opportunity") + +print "DB opened" + +db.wipe + +print "Wiped" + +db.close + +db = new OpportunityDB.open("opportunity") + +var hj = new People("Jack", "Handsome") + +var m = new Meetup("Awaken the warrior", "2024/05/28", "Vault of the Warrior") +assert m.commit(db) + +var vh = new People("Hunter", "Vault") + +var ll = new People("", "Lilith") + +var y = new Answer("Yes") +y.meetup = m +y.commit(db) + +var n = new Answer("No") +n.meetup = m +n.commit(db) + +var h = new Answer("I have no choice, I'm a hostage") +h.meetup = m +h.commit(db) + +hj.answer(y) = true +hj.answer(n) = false +hj.answer(h) = false + +vh.answer(y) = true +vh.answer(n) = false +vh.answer(h) = false + +ll.answer(y) = true +ll.answer(n) = false +ll.answer(h) = true + +hj.commit db +vh.commit db +ll.commit db + +assert hj.commit(db) +assert vh.commit(db) +assert ll.commit(db) + +print db.find_meetup_by_id(m.id) or else "null" + +for i in m.participants(db) do + print "Answers for {i.to_s.trim}" + i.load_answers(db, m) + for k,v in i.answers do + print "{k.to_s.trim} => {v.to_s.trim}" + end +end + +db.close diff --git a/contrib/opportunity/tests/sav/db_tests.res b/contrib/opportunity/tests/sav/db_tests.res new file mode 100644 index 0000000..1667896 --- /dev/null +++ b/contrib/opportunity/tests/sav/db_tests.res @@ -0,0 +1,18 @@ +Opening DB +DB opened +Wiped +Event : Awaken the warrior +When : 2024/05/28 +Where : Vault of the Warrior +Answers for Handsome Jack +Yes => true +No => false +I have no choice, I'm a hostage => false +Answers for Vault Hunter +Yes => true +No => false +I have no choice, I'm a hostage => false +Answers for Lilith +Yes => true +No => false +I have no choice, I'm a hostage => true -- 1.7.9.5