コード例 #1
0
func TestVarIDValueSymbolsAdd(t *testing.T) {
	symbols := NewVarIDValueSymbols()
	exampleVarID := vari.NewVarID("testIdentifier")
	exprExample := expr.NewSub(expr.NewIntegerLiteral(1), expr.NewIntegerLiteral(2))
	symbols.SetExprForVarID(exprExample, exampleVarID)

	if lookupExprValue := symbols.ExprForVarID(exampleVarID); lookupExprValue != exprExample {
		t.Errorf("VarIDValueSymbols not updated correctly, expected value %s for key %s, is %s", exprExample, exampleVarID, lookupExprValue)
	}
}
コード例 #2
0
func TestComputedQuestion(t *testing.T) {
	exampleLabel := expr.NewStringLiteral("Value residue")
	exampleVarDecl := vari.NewVarDecl(vari.NewVarID("hasSoldHouse"), expr.NewIntegerType())
	exampleComputation := expr.NewSub(expr.NewIntegerLiteral(10), expr.NewIntegerLiteral(5))

	exampleQuestion := NewComputedQuestion(exampleLabel, exampleVarDecl, exampleComputation)

	assert.Equal(t, exampleQuestion.Label(), exampleLabel)
	assert.Equal(t, exampleQuestion.Computation(), exampleComputation)
}
コード例 #3
0
func (suite *TypeCheckerTestSuite) TestUndefinedQuestionReferenceChecker() {
	computedQuestion := stmt.NewComputedQuestion(expr.NewStringLiteral("Value residue:"), vari.NewVarDecl(vari.NewVarID("valueResidue"), expr.NewIntegerType()), expr.NewSub(expr.NewIntegerLiteral(100), expr.NewVarExpr(vari.NewVarID("hasMaintLoan"))))
	exampleBody := stmt.NewStmtList([]interfaces.Question{computedQuestion}, []interfaces.Conditional{})
	exampleForm := stmt.NewForm(vari.NewVarID("TestForm"), exampleBody)

	suite.testThatNumberOfErrorsOfPassedTypeArePresentForForm(exampleForm, errors.UndefinedQuestionReferenceError{}, 1)
}
コード例 #4
0
func (suite *TypeCheckerTestSuite) TestInvalidOperandsCheckerForDifferentOperandEvalTypes() {
	exampleExpr := expr.NewSub(expr.NewBoolLiteral(true), expr.NewIntegerLiteral(10))

	suite.testThatNumberOfErrorsOfPassedTypeArePresentForExpr(exampleExpr, errors.OperandWithUnexpectedTypeError{}, 1)
}
コード例 #5
0
func TestFormComputedQuestion(t *testing.T) {
	exampleFormInput := "form TestForm { \"Did you sell a house in 2010?\" hasSoldHouse: integer \"Did you enter a loan?\" hasMaintLoan: integer \"Value residue:\" valueResidue: integer = (hasSoldHouse - hasMaintLoan) }"

	firstQuestionOutput := stmt.NewInputQuestion(expr.NewStringLiteral("Did you sell a house in 2010?"), vari.NewVarDecl(vari.NewVarID("hasSoldHouse"), expr.NewIntegerType()))
	secondQuestionOutput := stmt.NewInputQuestion(expr.NewStringLiteral("Did you enter a loan?"), vari.NewVarDecl(vari.NewVarID("hasMaintLoan"), expr.NewIntegerType()))
	computedQuestion := stmt.NewComputedQuestion(expr.NewStringLiteral("Value residue:"), vari.NewVarDecl(vari.NewVarID("valueResidue"), expr.NewIntegerType()), expr.NewSub(expr.NewVarExpr(vari.NewVarID("hasSoldHouse")), expr.NewVarExpr(vari.NewVarID("hasMaintLoan"))))
	exampleBodyOutput := stmt.NewStmtList([]interfaces.Question{firstQuestionOutput, secondQuestionOutput, computedQuestion}, []interfaces.Conditional{})
	exampleOutputForm := stmt.NewForm(vari.NewVarID("TestForm"), exampleBodyOutput)

	testStmtParse(t, exampleFormInput, exampleOutputForm)
}
コード例 #6
0
func NewSubNode(lhs attrib, rhs attrib, sourcePosInfo attrib) (interfaces.Expr, error) {
	expr := expr.NewSub(lhs.(interfaces.Expr), rhs.(interfaces.Expr))
	expr.SetSourceInfo(sourcePosInfo.(token.Pos))
	return expr, nil
}