// VisitIntegerType returns a GUI element for integers when question type is integer
func (this *QuestionTypeToGUIElementVisitor) VisitIntegerType(i interfaces.IntegerType, context interface{}) interface{} {
	var UIEntity ui.Control
	inputField := createInputTextField("", this.disabled)
	inputField.OnChanged(func(*ui.Entry) {
		inputText := inputField.Text()

		log.WithFields(log.Fields{"value": inputText}).Debug("Input text value changed (integer field)")

		inputTextAsInt, err := strconv.Atoi(inputText)
		if inputText == "" {
			if this.callback != nil {
				this.callback(expr.NewIntegerLiteral(inputTextAsInt), nil)
			}
			return
		} else if err != nil {
			log.Warn("Could not convert input text string to int")

			if this.callback != nil {
				this.callback(nil, err)
			}

			return
		}

		if this.callback != nil {
			this.callback(expr.NewIntegerLiteral(inputTextAsInt), nil)
		}
	})

	UIEntity = inputField

	return UIEntity
}
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)
	}
}
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)
}
func NewIntegerLiteralNode(litValueToken attrib) (interfaces.Expr, error) {
	sourcePosInfo := litValueToken.(*token.Token).Pos
	value, err := util.IntValue(litValueToken.(*token.Token).Lit)
	expr := expr.NewIntegerLiteral(int(value))
	expr.SetSourceInfo(sourcePosInfo)
	return expr, err
}
func (suite *TypeCheckerTestSuite) TestNonBoolConditionalChecker() {
	exampleQuestion := stmt.NewInputQuestion(expr.NewStringLiteral("Did you sell a house in 2010?"), vari.NewVarDecl(vari.NewVarID("hasSoldHouse"), expr.NewBoolType()))
	exampleIf := stmt.NewIf(expr.NewIntegerLiteral(10), stmt.NewStmtList([]interfaces.Question{exampleQuestion}, []interfaces.Conditional{}))
	exampleBody := stmt.NewStmtList([]interfaces.Question{}, []interfaces.Conditional{exampleIf})
	exampleForm := stmt.NewForm(vari.NewVarID("TestForm"), exampleBody)

	suite.testThatNumberOfErrorsOfPassedTypeArePresentForForm(exampleForm, errors.NonBooleanConditionError{}, 1)
}
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)
}
func (suite *TypeCheckerTestSuite) TestInvalidOperandsCheckerForInvalidBinaryOperationWithIntegers() {
	exampleExpr := expr.NewAnd(expr.NewIntegerLiteral(10), expr.NewIntegerLiteral(8))
	suite.testThatNumberOfErrorsOfPassedTypeArePresentForExpr(exampleExpr, errors.OperandWithUnexpectedTypeError{}, 2)
}
func (suite *TypeCheckerTestSuite) TestInvalidOperandsCheckerForDifferentOperandEvalTypes() {
	exampleExpr := expr.NewSub(expr.NewBoolLiteral(true), expr.NewIntegerLiteral(10))

	suite.testThatNumberOfErrorsOfPassedTypeArePresentForExpr(exampleExpr, errors.OperandWithUnexpectedTypeError{}, 1)
}
func (suite *TypeCheckerTestSuite) TestQuestionTypeAndComputationTypeMismatch() {
	exampleQuestion := stmt.NewComputedQuestion(expr.NewStringLiteral("Did you sell a house in 2010?"), vari.NewVarDecl(vari.NewVarID("hasSoldHouse"), expr.NewBoolType()), expr.NewIntegerLiteral(11))
	exampleBody := stmt.NewStmtList([]interfaces.Question{exampleQuestion}, []interfaces.Conditional{})
	exampleForm := stmt.NewForm(vari.NewVarID("TestForm"), exampleBody)

	suite.testThatNumberOfErrorsOfPassedTypeArePresentForForm(exampleForm, errors.DeclaratedTypeAndActualTypeDeviateError{}, 1)
}