From af8453d6e7cd882315b63c629b381f8b7a92404a Mon Sep 17 00:00:00 2001 From: Linus Oleander Date: Sun, 20 Feb 2011 16:13:33 +0100 Subject: [PATCH] Adding some new info to the ignore file --- .DS_Store | Bin 6148 -> 6148 bytes .gitignore | 3 +- BeverageWare.jr~ | 0 Door.jr~ | 218 ----------------------------------------------- Global.jr~ | 43 ---------- Item.jr~ | 0 Person.jr~ | 0 Table.jr~ | 165 ----------------------------------- 8 files changed, 1 insertion(+), 428 deletions(-) delete mode 100644 BeverageWare.jr~ delete mode 100644 Door.jr~ delete mode 100644 Global.jr~ delete mode 100644 Item.jr~ delete mode 100644 Person.jr~ delete mode 100644 Table.jr~ diff --git a/.DS_Store b/.DS_Store index ef1948590b4eb733ab43dc98e37dc872086ec6ad..d59fa8556611188a8e794d666568f1c640600d34 100644 GIT binary patch delta 192 zcmZoMXfc=|#>B)qu~2NHo}wrd0|Nsi1A_oVaY0f}eiD$kA*o>VMaJcflMO^zgqayK z8FCrYlgbg&la&~gxh1Qs4GqoAbQBB?C-*YSvewqsH#AOO&nPe53^an3A&a4i!JQ$M qA&+>SjLkr6vspH?bMSKj-3R1+XP(S2V#xt?9uP4wYz`3F!VCbVVKIyV delta 134 zcmZoMXfc=|#>B`mu~2NHo}wrt0|NsP3osNHB<18M0eNea3MLjV7Y9i&Gh{O4GNdP! zBP1ukVM^u@tFAUPG0;(%Jb_7;wW_+Nwr+9_vpi$N=7r2@ESonlUt-+M&cV+Cv;`>g Woq009h$RQmIFLn5n*&6)FarPsU?P10 diff --git a/.gitignore b/.gitignore index 46f18ec..25b2e77 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ .DS_Store *~ -jrGen +jrGen/* *#*# *.class *swp .goutput* - diff --git a/BeverageWare.jr~ b/BeverageWare.jr~ deleted file mode 100644 index e69de29..0000000 diff --git a/Door.jr~ b/Door.jr~ deleted file mode 100644 index af10509..0000000 --- a/Door.jr~ +++ /dev/null @@ -1,218 +0,0 @@ -import edu.ucdavis.jr.*; -import java.util.*; -import java.util.ArrayList; - - -public class Door { - - private ArrayList entrants; - private boolean isLocked; - private cap void() returnOkCap; - - - public op boolean add(Person p); - public op ArrayList lock(cap void() returnOkCap); - public op void leave(Person p); - - - public Door() { - entrants = new ArrayList(); - isLocked = false; - Global.door = this; - - } - - private process doorProcess { - startLoop(); - System.out.println("Door process exits ..."); - } - - - - // I added this as a seperate method to be able to override stupid warnings - @SuppressWarnings("unchecked") - private void startLoop() - { - while(true) - { - inni ArrayList lock(cap void() returnOkCap) - { - isLocked = true; - this.returnOkCap = returnOkCap; - - return new ArrayList(entrants); // This adds stupid warning - - } - [] boolean add(Person p) - { - if(isLocked) - { - return false; - } - addPersonToList(p); - return true; - - } - [] void leave(Person p) - { - removePersonFromList(p); - if(isLocked && entrants.size() == 1) - { - // Ok, only landlord should be left, lets notift him - send returnOkCap(); - } - if(isLocked && entrants.size() == 0) - { - // Ok, now even landlord left, lets exit gracfully - break; - } - } - } - } - - - @SuppressWarnings("unchecked") - private void addPersonToList(Person p) - { - entrants.add(p); // This darn command adds stupid warning - } - - - @SuppressWarnings("unchecked") - private void removePersonFromList(Person p) - { - entrants.remove(p); // This darn command adds stupid warning - } - - - - - - - - - - - - - - /*************************************************** - TESTING CODE BELOW - - ***************************************************/ - public static void main(String[] args) { - allDoorTests(); - } - - public static void allDoorTests() - { - testOnePersonEnters(); - testOnePersonLeaving(); - testDoor(); - System.out.println("Door tests passed."); - } - - // This test is starting other threads - public static void testOnePersonEnters() - { - Door d = new Door(); - asserts(d.entrants.size() == 0, "Door should start empty"); - Person p = new Person(true); - - JR.nap(10); - - asserts(d.entrants.get(0) == p, "Person p should be in list"); - asserts(d.entrants.size() == 1, "Should only be 1 person in list"); - - } - - // This test is starting other threads - public static void testOnePersonLeaving() - { - Door d = new Door(); - Person p = new TestPerson(); - - JR.nap(10); - p.leaveBar(); - JR.nap(10); - - asserts(d.entrants.size() == 0, "Everyone should have exited."); - } - - - // This test runs in a two threads (test+Doorprocess) and only emulates a person - // What is good with this test is that it doesn't depend on Person - // This test tests most behavior - public static void testDoor() - { - Door d = new Door(); - Person p1 = new TestPerson(); //fakeperson - asserts(d.add(p1), "Door should start open"); // try enter door - asserts(d.entrants.size() == 1, "Should only be 1 person in list"); - - Person p2 = new TestPerson(); // another entrant - d.add(p2); - asserts(d.entrants.size() == 2, "Two should 've entered"); - asserts(d.entrants.contains(p1), "p1 should be in list"); - asserts(d.entrants.contains(p2), "p2 should be in list"); - - - Person landlord = new TestPerson(); // this emulates Landlord (auto-enters) - op void returnCap(); // The landlords replyChannel - ArrayList list = d.lock(returnCap); - asserts(list != d.entrants, "Should not be reference to entrants!"); - asserts(list.equals(d.entrants), "Should however be equal to entrants!"); - - Person p3 = new TestPerson(); // this one will emulate door-rejected customer - asserts(!d.add(p3), "Door is locked, p3 should be rejected"); - asserts(d.entrants.size() == 3, "Nobody should've entered yet since it was locked (2persons + landlord is in)"); - - - // Now let p1 leave - d.leave(p1); - asserts(d.entrants.size() == 2, "only 1 + landlord should be left"); - asserts(d.entrants.contains(p2), "p2 should be left"); - - JR.nap(10); - - // make sure we haven't got reply yet - inni void returnCap() - { - asserts(false, "The closing signal is sent too early!"); - } - [] else { /* landing here is good :) */ } - - - - // Now let p2 leave - d.leave(p2); - asserts(d.entrants.size() == 1, "Only landlord should be in!"); - asserts(d.entrants.contains(landlord), "Only landlord should be in"); - - JR.nap(10); - - // make sure we HAVE got reply now - inni void returnCap() - { /* landing here is good :) */ } - [] else { - asserts(false, "The closing signal was not sent!"); - } - - d.leave(landlord); - - asserts(d.entrants.isEmpty(), "Everyone should've leaved"); - } - - - - - public static void asserts(boolean b, String s) - { - if(!b) - { - System.out.println("DoorAssert failed: " + s); - System.exit(1); - } - } - -} diff --git a/Global.jr~ b/Global.jr~ deleted file mode 100644 index f6bd736..0000000 --- a/Global.jr~ +++ /dev/null @@ -1,43 +0,0 @@ -import edu.ucdavis.jr.*; -import java.util.*; - -public class Global { - - // Global objects in the bar - public static Door door; - - - // Constants - public static int tableCapacities = 10; - - // Private constants - private static int BEER_DRINKING_TIME = 100; - private static int CAPPUCINO_DRINKING_TIME = 100; - private static int CHOCLATE_DRINKING_TIME = 100; - - - - // Ingredients - public static Item beerTap = new Item("Beer tap"); - public static Item coffee = new Item("Coffee"); - public static Item milk = new Item("Milk"); - public static Item cholcatePowder = new Item("Cholcate Powder"); - - // Beveragewares - public static BeverageWare glass = new BeverageWare("Glass", 2); - public static BeverageWare cup = new BeverageWare("Cup", 1); - - // Required Ingredients - private static Item[] beerIngredients = {}; - private static Item[] cappucinoIngredients = {}; - private static Item[] choclateIngredients = {}; - - - - // Beverages - public static Beverage beer = new Beverage("Beer", BEER_DRINKING_TIME, glass, beerIngredients); - public static Beverage cappucino = new Beverage("Cappucino", CAPPUCINO_DRINKING_TIME, cup, cappucinoIngredients); - public static Beverage choclate = new Beverage("Choclate", CHOCLATE_DRINKING_TIME, cup, choclateIngredients); - - -} diff --git a/Item.jr~ b/Item.jr~ deleted file mode 100644 index e69de29..0000000 diff --git a/Person.jr~ b/Person.jr~ deleted file mode 100644 index e69de29..0000000 diff --git a/Table.jr~ b/Table.jr~ deleted file mode 100644 index 2f0e1f9..0000000 --- a/Table.jr~ +++ /dev/null @@ -1,165 +0,0 @@ -import edu.ucdavis.jr.*; -import java.util.*; -import java.util.ArrayList; - - -public class Table { - - private ArrayList beveragewares; - private int capacity; - private static int startId = 0; - private int id; - - - public op void addBeverageWare(BeverageWare bw); - public op ArrayList clearTable(); - - - public Table() { - beveragewares = new ArrayList(); - id = startId++; - capacity = Global.tableCapacities; - } - - - @Override - public String toString() { - return "Table " + id; - } - - private process tableProcess { - startLoop(); - System.out.println("Table process exits ..."); - } - - - - //@SuppressWarnings("unchecked") - private void startLoop() - { -// while(true) -// { -// } - } - - - @SuppressWarnings("unchecked") - private void addBeverage(BeverageWare bw) - { - beveragewares.add(bw); // This darn command adds stupid warning - } - - private int unitsRemaining() - { - int taken = 0; - for (BeverageWare bw: beveragewares) { - taken += bw.getSpaceUnits(); - } - - asserts(capacity >= taken, "Table got overfilled!"); - return capacity - taken; - } - - - - - - - - - /*************************************************** - TESTING CODE BELOW - - ***************************************************/ - public static void main(String[] args) { - allTableTests(); - } - - public static void allTableTests() - { - testCapacityCounting(); - testOverflowTable(); - testClear(); - System.out.println("Table tests passed."); - } - - // This test just tests that glasses and mugs get counted appropriately - // Note how we in test use send but in testing never uses call - public static void testCapacityCounting() - { - Table t = new Table(); - t.capacity = 10; - asserts(t.unitsRemaining() == 10, "Table should start empty"); - - send t.addBeverageWare(Global.glass); JR.nap(10); - asserts(t.unitsRemaining() == 8, "8"); - - send t.addBeverageWare(Global.glass); JR.nap(10); - asserts(t.unitsRemaining() == 8, "8"); - - send t.addBeverageWare(Global.glass); JR.nap(10); - asserts(t.unitsRemaining() == 6, "6"); - - send t.addBeverageWare(Global.cup); JR.nap(10); - asserts(t.unitsRemaining() == 5, "5"); - - send t.addBeverageWare(Global.glass); JR.nap(10); - asserts(t.unitsRemaining() == 3, "3"); - } - - public static void testOverflowTable() - { - Table t = new Table(); - t.capacity = 3; - - send t.addBeverageWare(Global.glass); JR.nap(10); - - send t.addBeverageWare(Global.glass); JR.nap(10); - asserts(t.unitsRemaining() == 1, "A 1-unit-remaining table should not take in another glass!"); - - send t.addBeverageWare(Global.cup); JR.nap(10); - asserts(t.unitsRemaining() == 0, "A 1-unit-remaining table should be able to take a cup!"); - - send t.addBeverageWare(Global.cup); JR.nap(10); - asserts(t.unitsRemaining() == 0, "A full table should not be able to take in cups"); - - } - - public static void testClear() - { - Table t = new Table(); - t.capacity = 6; - - send t.addBeverageWare(Global.glass); JR.nap(10); - send t.addBeverageWare(Global.cup); JR.nap(10); - send t.addBeverageWare(Global.glass); JR.nap(10); - send t.addBeverageWare(Global.glass); JR.nap(10); // Now this one should not be put in until after clearance - - ArrayList list = t.clearTable(); JR.nap(10); - asserts(t.unitsRemaining() == 6, "A cleared table should be clear."); - - asserts(list != t.beveragewares, "Should not return reference list on clearing."); - asserts(list.size() == 3, "Should retrieved all 3 beveragewares"); - - // The 3 asserts below are not senseful as they should test multi-setproperties, but oh well ... - asserts(list.get(0) == Global.glass, "should be glass AND refernce"); - asserts(list.get(1) == Global.cup, "cup"); - asserts(list.get(0) == Global.glass, "glass"); - - // Now lets check if old sent glass got recieved - asserts(t.unitsRemaining() == 4, "Glass probably didn't get back on table"); - - - } - - - - public static void asserts(boolean b, String s) - { - if(!b) - { - System.out.println("TableAssert failed: " + s); - System.exit(1); - } - } -}