use of java.util.Stack in project pcgen by PCGen.
the class OrCommandTest method testOr02.
/* Test the case where the first operand is false, but the second is true */
public void testOr02() {
final PostfixMathCommandI c = new OrCommand();
final Stack<Double> s = new Stack<>();
s.push(0.0);
s.push(2.0);
c.setCurNumberOfParameters(2);
runOr(s, c);
final Double result = s.pop();
is(result, eq(2.0, 0.1), "if (0.0,2.0) returns 2.0");
}
use of java.util.Stack in project pcgen by PCGen.
the class OrCommandTest method testOr01.
/* Test the case where the first operand is true */
public void testOr01() {
final PostfixMathCommandI c = new OrCommand();
final Stack<Object> s = new Stack<>();
s.push(1.0);
s.push(2.0);
c.setCurNumberOfParameters(2);
runOr(s, c);
final Double result = (Double) s.pop();
is(result, eq(1.0, 0.1), "if (1.0,2.0) returns 1.0");
}
use of java.util.Stack in project pcgen by PCGen.
the class OrCommandTest method testOr05.
/* Test the case where false and zero are skipped */
public void testOr05() {
final PostfixMathCommandI c = new OrCommand();
final Stack s = new Stack();
s.push(false);
s.push(false);
s.push(false);
s.push(false);
c.setCurNumberOfParameters(4);
runOr(s, c);
final Object result = s.pop();
is(result, new CompareEqualDouble(0.0), "if (false,false,false,false) returns 0.0");
}
use of java.util.Stack in project pcgen by PCGen.
the class OrCommand method run.
/**
* @param inStack
* Stack of incoming arguments.
* @throws ParseException
*/
@Override
@SuppressWarnings({ "unchecked" })
public //Uses JEP, which doesn't use generics
void run(final Stack inStack) throws ParseException {
// check the stack
checkStack(inStack);
// Check if stack is null
if (null == inStack) {
throw new ParseException("Stack argument null");
}
final Stack newStack = new Stack();
int paramCount = curNumberOfParameters;
while (paramCount > 0) {
paramCount--;
newStack.push(inStack.pop());
}
int paramCount1 = curNumberOfParameters;
Object result = 0.0;
while (paramCount1 > 0) {
paramCount1--;
final Object operand = newStack.pop();
// If we're haven't found a true value yet
if (operand instanceof Number) {
if (((Number) operand).doubleValue() != 0.0d) {
result = operand;
break;
}
} else if (operand instanceof Boolean) {
if ((Boolean) operand) {
result = operand;
break;
}
} else {
throw new ParseException("Invalid parameter type for: " + operand);
}
}
// finally, put back the result
inStack.push(result);
}
use of java.util.Stack in project Main by SpartanRefactoring.
the class PropositionTest method hasCycles.
private boolean hasCycles(final BooleanSupplier s) {
final Stack<BooleanSupplier> path = new Stack<>();
path.add(s);
final Queue<BooleanSupplier> todo = new LinkedList<>();
do {
final BooleanSupplier current = todo.isEmpty() ? path.pop() : todo.remove();
if (path.contains(current))
return true;
if (current instanceof Proposition.Some) {
todo.addAll(((Proposition.Some) current).inner);
continue;
}
if (current instanceof Proposition.Singleton)
path.push(((Proposition.Singleton) current).inner);
} while (!path.isEmpty());
return false;
}
Aggregations