Esempio n. 1
0
  @Test
  public void testSizeIncrement() {
    bag.add(test, 1);
    bag.add(test1, 1);

    Assert.assertEquals(2, bag.size());

    bag.add(test1, 3);

    Assert.assertEquals(5, bag.size());
  }
Esempio n. 2
0
  @Test
  public void testSingularRemoval() {
    bag.add(test, 5);

    Assert.assertTrue(bag.remove(test));
    Assert.assertEquals(4, bag.size());
  }
Esempio n. 3
0
  @Test
  public void testGetCount() {
    Bag<String> bag = new Bag<>();
    String test = "Hello World";
    bag.add(test, 5);

    Assert.assertEquals(5, bag.getCount(test));
  }
Esempio n. 4
0
  @Test
  public void testIsEmpty() {
    Assert.assertTrue(bag.isEmpty());

    bag.add("Hello World");

    Assert.assertFalse(bag.isEmpty());
  }
Esempio n. 5
0
  @Test
  public void testMultipleRemoval() {
    bag.add(test, 5);

    Assert.assertTrue(bag.remove(test, 3));
    Assert.assertEquals(2, bag.size());
    Assert.assertTrue(bag.remove(test));
    Assert.assertEquals(1, bag.size());
  }
  private UpperclassHousingSelection() {

    dorms = new Bag();

    // actually mixed-year but for simplicity I'm keeping it
    // upperclassman only for now
    Dorm Arrington = new Dorm("Arrington", false, false, 74);

    Dorm Ball = new Dorm("Ball", true, false, 53);
    Dorm Custis = new Dorm("Custis", false, false, 21);
    Dorm EagleLanding = new Dorm("Eagle Landing", false, false, 312);
    Dorm Framar = new Dorm("Framar", false, false, 11);
    Dorm Madison = new Dorm("Madison", false, false, 21);
    Dorm Marshall = new Dorm("Marshall", false, false, 74);
    Dorm Mason = new Dorm("Mason", false, false, 93);
    Dorm Westmoreland = new Dorm("Westmoreland", false, false, 56);

    // Willard houses students in single rooms which is not accounted for yet
    Dorm Willard = new Dorm("Willard", false, false, 91);

    // 100 of the rooms in the aparments are singles which is not
    // accounted for yet
    Dorm Apartments = new Dorm("Apartments", false, false, 381);

    // for extraneous students who commute or live off campus
    Dorm Offcampus = new Dorm("Offcampus", false, false, 3500);

    dorms.add(Ball);
    dorms.add(Arrington);
    dorms.add(Custis);
    dorms.add(Framar);
    dorms.add(Madison);
    dorms.add(Mason);
    dorms.add(Westmoreland);
    dorms.add(Willard);
    dorms.add(Apartments);
    dorms.add(EagleLanding);
    dorms.add(Offcampus);
  }
Esempio n. 7
0
 @Test
 public void add0Items() {
   Assert.assertFalse(bag.add("Zero", 0));
 }
Esempio n. 8
0
 @Test
 public void testAddDuplicate() {
   bag.add(test, 5);
   bag.add(test, 5);
   Assert.assertEquals(10, bag.getCount(test));
 }
Esempio n. 9
0
 @Test
 public void testSimpleAdd() {
   Assert.assertTrue(bag.add("Hello World"));
 }
Esempio n. 10
0
 @Test
 public void testRemovalOfNotAddedObject() {
   bag.add("Added");
   Assert.assertFalse(bag.remove("Not Added"));
 }
Esempio n. 11
0
  // main CELL CA loop************
  public boolean iterateCells() {
    /*
    	// modify consumption matrix
    	    	for (int i=0;i<size;i++)
    	        for (int j=0;j<size;j++) consumption[i][j] = consumptionBasal[Cells[i][j]];
    */
    //
    if (cellList == null) cellList = new Bag(size * size);
    for (int i = 0; i < size; i++)
      for (int j = 0; j < size; j++) {
        if (Cells[i][j]
            < 4) { // All tumour cell types have Cell > 0, now 0 corresponds to 'healthy cells' that
          // consume at basal rate only
          int[] p = new int[2];
          p[0] = i;
          p[1] = j;
          cellList.add(p);
          if (Cells[i][j] == 1) {
            stem_cells_this_TS++;
          } else if (Cells[i][j] == 2 || Cells[i][j] == 3) {
            non_stem_cells_this_TS++;
          }
        }
      }

    while (cellList.size() != 0) {
      // Select the next lattice element at random
      int randomElemIndex = 0;
      if (cellList.size() > 1) randomElemIndex = random.nextInt(cellList.size() - 1);
      int[] point = (int[]) cellList.get(randomElemIndex);
      int rI = point[0];
      int rJ = point[1];

      cellList.remove(randomElemIndex); // Remove it from the cell list
      int cell = Cells[rI][rJ];

      // Cell death
      // if ((Oxygen[rI][rJ]<hypoxia)) {
      if ((random.nextFloat() < deathprob) && Cells[rI][rJ] > 0) { // x% chances of dying
        Age[rI][rJ] = 0;
        if (Cells[rI][rJ] == 1) stemDeathCounter[rI][rJ]++;
        if (Cells[rI][rJ] < 4) {
          // TACDeathCounter[rI][rJ]++;
          Cells[rI][rJ] = 4; // was 0, now making necrotic area (truly empty)
          deaths++;
          stemBirthCounter[rI][rJ] = 0;
          carriedmutation[rI][rJ] = 0; // empty space now has no mutations
          carriedGenome[rI][rJ] = initGenome; // empty space now has no mutations
        }
      } else if ((cell == 3)
          && (Age[rI][rJ]
              > 100 * maxMatureCellAge)) { // added * to allow for an update each celltimestep/x
        // **************************
        Age[rI][rJ] = 0;
        Cells[rI][rJ] = 4; // was 0, now making necrotic area (truly empty)
        // TACDeathCounter[rI][rJ]++;
        deaths++;
      } else if ((radiotherapy) && (cell == 2) && (random.nextFloat() > Oxygen[rI][rJ])) {
        // Radiotherapy
        Age[rI][rJ] = 0;
        if (Cells[rI][rJ] == 1) stemDeathCounter[rI][rJ]++;
        if ((Cells[rI][rJ] == 2) || (Cells[rI][rJ] == 3))
          // TACDeathCounter[rI][rJ]++;
          Cells[rI][rJ] = 4; // make necrotic
        stemBirthCounter[rI][rJ] = 0;
        deaths++;
      }

      // healthy division
      else if ((cell == 0) && (vacantSites(rI, rJ) > 0)) {
        if (proliferation[cell]
            >= random.nextFloat()) { // If tossing the coin we are to proliferate...
          // if (Oxygen[rI][rJ]>prolifThreshold) { // AND the oxygen concentration is enough for
          // division..
          // consumption[rI][rJ]=consumptionDivision[Cells[rI][rJ]];
          int[] daughter = findEmptySite(rI, rJ);
          births++;
          Cells[daughter[0]][daughter[1]] = 0;
          carriedmutation[daughter[0]][daughter[1]] = 0;
          carriedGenome[daughter[0]][daughter[1]] =
              initGenome; // resetting space to healthy cell with no mutations
        }
      }
      // }

      // cancer division
      else if ((vacantSitesCancer(rI, rJ) > 0) && (cell > 0))
        if (proliferation[cell]
            >= random.nextFloat()) { // If tossing the coin we are to proliferate...
          if ((cell == 1)
              || ((cell == 2)
                  && (Age[rI][rJ] < maxProDivisions))) { // AND the cell is stem or TAC ...
            // if (Oxygen[rI][rJ]>prolifThreshold) { // AND the oxygen concentration is enough for
            // division..
            // consumption[rI][rJ]=consumptionDivision[Cells[rI][rJ]];
            int[] daughter = findEmptySiteCancer(rI, rJ); // and there is space (for cancer)
            //    if ((daughter[0]==0) || (daughter[0]==size) ||
            // (daughter[1]==0)||(daughter[1]==size)) {simulationFinished=true;} // stop sim if a
            // cell hits the edge
            births++;
            if (cell == 1) { // stem cell
              stemBirthsTotal[rI][rJ]++;
              stemBirthCounter[rI][rJ]++;
              if (asymmetricRatio > random.nextFloat()) {
                Cells[daughter[0]][daughter[1]] = 1; // placing the stem daughter
                stemBirthCounter[daughter[0]][daughter[1]] =
                    stemBirthCounter[rI][rJ]; // update stem birth counter
                carriedmutation[daughter[0]][daughter[1]] =
                    carriedmutation[rI][rJ]; // inherit mutational status of parent
                carriedGenome[daughter[0]][daughter[1]] =
                    carriedGenome[rI][rJ]; // inherit mutational status of parent
                if (mutfreq > random.nextFloat()) { // small chance of mutation
                  mutationNum++; // advance mutation number
                  System.out.println(
                      +carriedmutation[rI][rJ]
                          + ", "
                          + mutationNum
                          + ", "
                          + stem_cells_this_TS
                          + ", "
                          + non_stem_cells_this_TS
                          + ", "
                          + timestep); // print (parent,child) pair
                  // tree.put(carriedmutation[rI][rJ], mutationNum);
                  // timeTree.put(mutationNum, timestep); // hash table stuff
                  if (0.5 > random.nextFloat()) {
                    carriedmutation[daughter[0]][daughter[1]] = mutationNum;
                    genomeToMod = new StringBuilder(carriedGenome[daughter[0]][daughter[1]]);
                    genomeToMod.setCharAt(
                        mutationNum - 1, '1'); //  daughter carries new carriedGenome
                    carriedGenome[daughter[0]][daughter[1]] = genomeToMod;
                    // System.out.println (carriedGenome[rI][rJ]);
                    // System.out.println (carriedGenome[daughter[0]][daughter[1]]);
                  } // 50:50 mutate new position daughter
                  else {
                    carriedmutation[rI][rJ] = mutationNum; // else mutate original position daughter
                    genomeToMod = new StringBuilder(carriedGenome[rI][rJ]);
                    // genomeToMod = carriedGenome[rI][rJ];
                    carriedGenome[rI][rJ] = genomeToMod;
                    genomeToMod.setCharAt(
                        mutationNum - 1, '1'); //  original carries new carriedGenome
                    // System.out.println (carriedGenome[rI][rJ]);
                    // System.out.println (carriedGenome[daughter[0]][daughter[1]]);
                  }
                }
              } else {
                Cells[daughter[0]][daughter[1]] = 2; // asymmetric division, daughter is TAC
                stemBirthCounter[daughter[0]][daughter[1]] = 0; // reset stem counter
                carriedmutation[daughter[0]][daughter[1]] =
                    carriedmutation[rI][rJ]; // TAC carries parental mutation flag
                carriedGenome[daughter[0]][daughter[1]] = carriedGenome[rI][rJ];
              } // TAC carries parental genome
              // } // redundant from above

              // else { // Only if there's hypoxia induced change of symmetric division ratio
              //    float newASR=asymmetricRatio+0*(hypoxia-Oxygen[rI][rJ]);
              // currently OFF by way of 0 the ^^ multiplier.
              //    if (newASR>random.nextFloat())
              // {Cells[daughter[0]][daughter[1]]=1;stemBirthCounter[daughter[0]][daughter[1]]=stemBirthCounter[rI][rJ];}
              //    else
              // {Cells[daughter[0]][daughter[1]]=2;stemBirthCounter[daughter[0]][daughter[1]]=0;}
              // // Otherwise differentiate
              // }
            } else if (cell == 2) { // non-stem division
              // TACBirthCounter[rI][rJ]++;
              if (Age[rI][rJ] < maxProDivisions - 1) {
                Cells[daughter[0]][daughter[1]] = 2;
                Age[rI][rJ]++;
                Age[daughter[0]][daughter[1]] = Age[rI][rJ];
                carriedmutation[daughter[0]][daughter[1]] =
                    carriedmutation[rI][rJ]; // TAC carries parental mutation flag
                carriedGenome[daughter[0]][daughter[1]] =
                    carriedGenome[rI][rJ]; // TAC carries parental genome
              } else {
                Cells[daughter[0]][daughter[1]] = 3;
                Cells[rI][rJ] = 3;
                Age[rI][rJ] = 0;
                Age[daughter[0]][daughter[1]] = Age[rI][rJ];
                carriedmutation[daughter[0]][daughter[1]] =
                    carriedmutation[rI][rJ]; // TAC carries parental mutation flag
                carriedGenome[daughter[0]][daughter[1]] =
                    carriedGenome[rI][rJ]; // TAC carries parental genome
              }
            }
          }
        } else if (pMotility > random.nextFloat()) { // Migration = not in use
          int[] daughter = findEmptySite(rI, rJ);
          Cells[daughter[0]][daughter[1]] = cell;
          Cells[rI][rJ] = 0;
          Age[daughter[0]][daughter[1]] = Age[rI][rJ];
          Age[rI][rJ] = 0;
          System.err.println("moving " + rI + ", " + rJ);
        }
      // Aging for mature cells
      if (cell == 3) Age[rI][rJ]++;
    }
    return true;
  }
Esempio n. 12
0
  /* Test the ArrayBag implementation. */
  public static void main(String[] args) {

    // Create a Scanner object for user input.
    Scanner in = new Scanner(System.in);

    // Create an ArrayBag named bag1.
    System.out.print("Size of bag 1: ");
    int size = in.nextInt();
    Bag bag1 = new ArrayBag(size);
    in.nextLine(); // consume the rest of the line

    // ****** Additions *****

    // Display capacity of new bag
    System.out.println("Bag 1 can hold up to " + bag1.capacity() + " items.");

    // Determine if ArrayBag is full
    if (bag1.isFull()) System.out.println("Bag is full.");
    else System.out.println("Bag is NOT full.");

    // Read in strings, add them to bag1, and print out bag1.
    String itemStr;
    for (int i = 0; i < size; i++) {
      System.out.print("item " + i + ": ");
      itemStr = in.nextLine();
      bag1.add(itemStr);
    }
    System.out.println("bag 1 = " + bag1);
    System.out.println();

    // Increase capacity by 2
    System.out.println("Increasing Bag 1 capacity by 2.");
    bag1.increaseCapacity(2);
    System.out.println("Bag 1 can hold up to " + bag1.capacity() + " items.");

    // Select a random item and print it.
    Object item = bag1.grab();
    System.out.println("grabbed " + item);
    System.out.println();

    // Iterate over the objects in bag1, printing them one per
    // line.
    Object[] items = bag1.toArray();
    for (int i = 0; i < items.length; i++) System.out.println(items[i]);
    System.out.println();

    // Get an item to remove from bag1, remove it, and reprint the bag.
    System.out.print("item to remove: ");
    itemStr = in.nextLine();
    if (bag1.contains(itemStr)) bag1.remove(itemStr);
    System.out.println("bag 1 = " + bag1);
    System.out.println();

    // Remove all items from bag1 and reprint the bag.
    Bag other1 = new ArrayBag(2);
    other1.add("ff");
    other1.add("aa");
    System.out.println("Removing all items {aa, ff}");
    bag1.removeItems(other1);
    System.out.println("bag 1 = " + bag1);
    System.out.println();

    // Create two ArrayBags and return their union (with no duplicates)
    // {2, 2, 3, 5, 7, 7, 7, 8}
    Bag b1 = new ArrayBag(8);
    b1.add("2");
    b1.add("2");
    b1.add("3");
    b1.add("5");
    b1.add("7");
    b1.add("7");
    b1.add("7");
    b1.add("8");
    System.out.println("Bag b1 is " + b1);

    // {2, 3, 4, 5, 5, 6, 7}
    Bag b2 = new ArrayBag(7);
    b2.add("2");
    b2.add("3");
    b2.add("4");
    b2.add("5");
    b2.add("5");
    b2.add("6");
    b2.add("7");
    System.out.println("Bag b2 is " + b2);

    // Be sure to test case with zero items
    Bag b3 = new ArrayBag();
    b3 = b1.unionWith(b2);
    System.out.println("Union of b1 & b2 is " + b3);
    System.out.println("b3 capacity is " + b3.capacity());
    System.out.println();
  }