Example #1
0
 @Test
 public void testParameterValue() {
   AnnotationValue value = mock(AnnotationValue.class);
   when(value.getParameterValue()).thenReturn("valid");
   Not expr = new Not(value);
   assertEquals("~valid", expr.getParameterValue());
 }
Example #2
0
File: Not.java Project: huxi/sulky
 public Not clone() throws CloneNotSupportedException {
   Not result = (Not) super.clone();
   if (result.condition != null) {
     result.condition = result.condition.clone();
   }
   return result;
 }
  public final void testTrueNegationSimplification() {
    True trueExp = new True();
    trueExp.type = BooleanType.instance;
    Not not = new Not(trueExp);
    not.type = BooleanType.instance;

    expressionSimplificationTester(not, False.class, BooleanType.instance, 0, false);
  }
  public final void testFalseNegationSimplification() {
    False falseExp = new False();
    falseExp.type = BooleanType.instance;
    Not not = new Not(falseExp);
    not.type = BooleanType.instance;

    expressionSimplificationTester(not, True.class, BooleanType.instance, 0, false);
  }
Example #5
0
 @Test
 public void testAccept() {
   ExpressionVisitor visitor = mock(ExpressionVisitor.class);
   Not expr = new Not(null);
   Object visitResult = new Object();
   when(visitor.visit(expr)).thenReturn(visitResult);
   assertSame(expr.accept(visitor), visitResult);
 }
    @Override
    public ConstantValue visitNot(Not expr, Void arg) {
      // Get the type of the result
      final ConstantType resultConstantType = typeFactory.newConstantType(expr.getType().get());

      // Perform the operation
      final boolean resultValue = !expr.getArgument().accept(this, null).logicalValue();
      return UnsignedIntegerConstantValue.getLogicalValue(resultValue).castTo(resultConstantType);
    }
  public final void testEvenConstantNegationSimplification() {
    False falseExp = new False();
    falseExp.type = BooleanType.instance;
    Not not1 = new Not(falseExp);
    not1.type = BooleanType.instance;
    Not not2 = new Not(not1);
    not2.type = BooleanType.instance;

    expressionSimplificationTester(not2, False.class, BooleanType.instance, 0, false);
  }
  public final void testEvenExpressionNegationSimplification() {
    MethodAccess callExp = new MethodAccess();
    callExp.expression = new This();
    callExp.type = BooleanType.instance;
    Not not1 = new Not(callExp);
    not1.type = BooleanType.instance;
    Not not2 = new Not(not1);
    not2.type = BooleanType.instance;

    expressionSimplificationTester(not2, MethodAccess.class, BooleanType.instance, 0, false);
  }
Example #9
0
    public AnotherCreatureEntersTheBattlefield(GameState state) {
      super(
          state,
          "Whenever another creature enters the battlefield under your control, if you control both that creature and this one and both are unpaired, you may pair that creature with this creature for as long as both remain creatures on the battlefield under your control.");
      SetGenerator thisCreature = ABILITY_SOURCE_OF_THIS;
      SetGenerator otherCreatures =
          RelativeComplement.instance(CreaturePermanents.instance(), thisCreature);
      this.addPattern(
          new SimpleZoneChangePattern(
              null, Battlefield.instance(), otherCreatures, You.instance(), false));

      SetGenerator thatCreature = NewObjectOf.instance(TriggerZoneChange.instance(This.instance()));
      SetGenerator youControl = ControlledBy.instance(You.instance());
      SetGenerator youControlUnpairedThis =
          Intersect.instance(youControl, Unpaired.instance(), thisCreature);
      SetGenerator youControlUnpairedThat =
          Intersect.instance(youControl, Unpaired.instance(), thatCreature);
      this.interveningIf = Both.instance(youControlUnpairedThis, youControlUnpairedThat);

      ContinuousEffect.Part part = new ContinuousEffect.Part(ContinuousEffectType.PAIR);
      part.parameters.put(
          ContinuousEffectType.Parameter.OBJECT, Union.instance(thisCreature, thatCreature));

      SetGenerator youControlCreatureThis = Intersect.instance(CREATURES_YOU_CONTROL, thisCreature);
      SetGenerator youControlCreatureThat = Intersect.instance(CREATURES_YOU_CONTROL, thatCreature);
      SetGenerator expires =
          Not.instance(Both.instance(youControlCreatureThis, youControlCreatureThat));
      EventFactory floatingEffect =
          createFloatingEffect(expires, "Pair this creature with that creature", part);

      this.addEffect(youMay(floatingEffect));
    }
  @Override
  public Boolean visit(Not ast) {
    boolean checkArg = ast.getArg().accept(this);

    if (!checkArg) return false;

    Type argType = ast.getArg().typeOf(env);

    if (!argType.isCompatibleToBool()) {
      addToErrorList(
          ast,
          "the unary operator ! can not be applied to instances of type " + argType.getClass());
      return false;
    }
    return true;
  }
 @Override
 public Boolean visit(Not exp) {
   Expr unExpr = exp.getExpr();
   if (!(unExpr.typeOf(environment) == new BoolType())) {
     errorMsgs.add(String.format("Not expression is not a boolean: %s", exp));
     return false;
   }
   return unExpr.accept(this);
 }
Example #12
0
 public static void init() {
   Add.init();
   Address.init();
   Align.init();
   Alloc.init();
   Anchor.init();
   And.init();
   Bad.init();
   Bitcast.init();
   Block.init();
   Builtin.init();
   Call.init();
   Cmp.init();
   Cond.init();
   Confirm.init();
   Const.init();
   Conv.init();
   CopyB.init();
   Deleted.init();
   Div.init();
   Dummy.init();
   End.init();
   Eor.init();
   Free.init();
   IJmp.init();
   Id.init();
   Jmp.init();
   Load.init();
   Member.init();
   Minus.init();
   Mod.init();
   Mul.init();
   Mulh.init();
   Mux.init();
   NoMem.init();
   Not.init();
   Offset.init();
   Or.init();
   Phi.init();
   Pin.init();
   Proj.init();
   Raise.init();
   Return.init();
   Sel.init();
   Shl.init();
   Shr.init();
   Shrs.init();
   Size.init();
   Start.init();
   Store.init();
   Sub.init();
   Switch.init();
   Sync.init();
   Tuple.init();
   Unknown.init();
 }
  @Override
  public ConfigurationRuleBuilder otherwise(Operation operation) {
    for (ConfigurationRuleBuilderInterceptor interceptor : interceptors) {
      operation = interceptor.otherwise(operation);
    }

    wrapped.addOtherwiseRule(rule).when(Not.any(rule)).perform(operation);

    return this;
  }
Example #14
0
    public DrawThreeDiscardThree(GameState state) {
      super(
          state,
          "Threshold \u2014 (U), (T), Sacrifice Cephalid Coliseum: Target player draws three cards, then discards three cards. Activate this ability only if seven or more cards are in your graveyard.");
      this.setManaCost(new ManaPool("U"));
      this.costsTap = true;
      this.addCost(sacrificeThis("Cephalid Coliseum"));

      Target target = this.addTarget(Players.instance(), "target player");
      this.addEffect(drawCards(targetedBy(target), 3, "Target player draws three cards,"));
      this.addEffect(discardCards(targetedBy(target), 3, "then discards three cards."));
      this.addActivateRestriction(Not.instance(Threshold.instance()));
    }
  @Override
  public ConfigurationRuleBuilderOtherwise otherwise(Operation operation, Operation... operations) {
    List<Operation> list = new LinkedList<Operation>();
    list.add(operation);
    list.addAll(Arrays.asList(operations));

    for (ConfigurationRuleBuilderInterceptor interceptor : interceptors) {
      list = interceptor.otherwise(list);
    }

    wrapped
        .addOtherwiseRule(rule)
        .when(Not.any(rule))
        .perform(Perform.all(list.toArray(new Operation[list.size()])));

    return this;
  }
Example #16
0
    public ThisEntersTheBattlefield(GameState state) {
      super(
          state,
          "When this creature enters the battlefield, if you control both this creature and another creature and both are unpaired, you may pair this creature with another unpaired creature you control for as long as both remain creatures on the battlefield under your control.");
      SetGenerator thisCreature = ABILITY_SOURCE_OF_THIS;
      this.addPattern(
          new SimpleZoneChangePattern(null, Battlefield.instance(), thisCreature, false));

      SetGenerator otherCreaturesYouControl =
          RelativeComplement.instance(CREATURES_YOU_CONTROL, thisCreature);
      SetGenerator youControl = ControlledBy.instance(You.instance());
      SetGenerator youControlUnpairedThis =
          Intersect.instance(youControl, Unpaired.instance(), thisCreature);
      SetGenerator youControlUnpairedOtherCreatures =
          Intersect.instance(Unpaired.instance(), otherCreaturesYouControl);
      this.interveningIf = Both.instance(youControlUnpairedThis, youControlUnpairedOtherCreatures);

      EventFactory choose =
          playerChoose(
              You.instance(),
              1,
              youControlUnpairedOtherCreatures,
              PlayerInterface.ChoiceType.OBJECTS,
              REASON,
              "Choose another unpaired creature you control");
      SetGenerator thatCreature = EffectResult.instance(choose);

      ContinuousEffect.Part part = new ContinuousEffect.Part(ContinuousEffectType.PAIR);
      part.parameters.put(
          ContinuousEffectType.Parameter.OBJECT, Union.instance(thisCreature, thatCreature));

      SetGenerator youControlCreatureThis = Intersect.instance(CREATURES_YOU_CONTROL, thisCreature);
      SetGenerator youControlCreatureThat = Intersect.instance(CREATURES_YOU_CONTROL, thatCreature);
      SetGenerator expires =
          Not.instance(Both.instance(youControlCreatureThis, youControlCreatureThat));
      EventFactory floatingEffect =
          createFloatingEffect(expires, "and pair this creature with the chosen creature.", part);

      this.addEffect(
          youMay(
              sequence(choose, floatingEffect),
              "You may pair this creature with another unpaired creature you control for as long as both remain creatures on the battlefield under your control."));
    }
Example #17
0
  public final void testOddExpressionNegationSimplification() {
    MethodAccess callExp = new MethodAccess();
    callExp.expression = new This();
    callExp.type = BooleanType.instance;
    Not not1 = new Not(callExp);
    not1.type = BooleanType.instance;
    Not not2 = new Not(not1);
    not2.type = BooleanType.instance;
    Not not3 = new Not(not2);
    not3.type = BooleanType.instance;

    Expression resultExp =
        expressionSimplificationTester(not3, Not.class, BooleanType.instance, 0, false);

    assertEquals(((Not) resultExp).expression.getClass(), MethodAccess.class);
  }
Example #18
0
    public EntwineAdditionalCost(GameState state, CostCollection costs, String costName) {
      super(
          state,
          "If you choose all the modes of this spell, you pay an additional " + costName + ".");

      this.costCollection = costs;
      this.costName = costName;

      Set newCosts = Set.fromCollection(costs.manaCost);
      newCosts.addAll(costs.events);

      ContinuousEffect.Part part = new ContinuousEffect.Part(ContinuousEffectType.COST_ADDITION);
      part.parameters.put(ContinuousEffectType.Parameter.OBJECT, This.instance());
      part.parameters.put(ContinuousEffectType.Parameter.COST, Identity.fromCollection(newCosts));
      this.addEffectPart(part);

      // This only applies if you've chosen all of its modes
      this.canApply =
          Not.instance(
              RelativeComplement.instance(
                  ModesOf.instance(This.instance()), SelectedModesOf.instance(This.instance())));
    }
 @Override
 public ConditionBuilder andNot(final Condition condition) {
   if (condition == null) return this;
   return And.all(this, Not.any(condition));
 }
 @Override
 public void visit(Not notExp) {
   System.out.print("!");
   if (notExp.getExp() != null) notExp.getExp().accept(this);
 }
 @Override
 public void meet(Not node) throws RuntimeException {
   builder.append("NOT (");
   node.getArg().visit(this);
   builder.append(")");
 }
 @Override
 public ConditionBuilder orNot(final Condition condition) {
   if (condition == null) return this;
   return Or.any(this, Not.any(condition));
 }
Example #23
0
 @Test
 public void testToString() {
   AnnotationValue value = mock(AnnotationValue.class);
   Not expr = new Not(value);
   assertEquals("~" + value, expr.toString());
 }