Search in sources :

Example 6 with QuestionDetails

use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.

the class DecimalWidgetTest method integerValueShouldDisplayNoDecimalPoint.

@Test
public // Fails when double is turned to string with toString or String.format(Locale.US, "%f", d))
void integerValueShouldDisplayNoDecimalPoint() {
    Double integerDouble = 0.;
    String integerString = "0";
    when(formEntryPrompt.getAnswerValue()).thenReturn(answerData);
    when(answerData.getValue()).thenReturn(integerDouble);
    DecimalWidget decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
    assertThat(decimalWidget.getAnswerText(), is(equalTo(integerString)));
    decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
    assertThat(decimalWidget.getAnswerText(), is(equalTo(integerString)));
}
Also used : QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails) Test(org.junit.Test) GeneralStringWidgetTest(org.odk.collect.android.widgets.base.GeneralStringWidgetTest)

Example 7 with QuestionDetails

use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.

the class DecimalWidgetTest method fifteenDigitNegativeValueShouldDisplayAllDigits.

@Test
public // https://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#toString(double)
void fifteenDigitNegativeValueShouldDisplayAllDigits() {
    Double fifteenDigitNegativeDouble = -99999999999999.;
    String fifteenDigitNegativeString = "-99999999999999";
    assertSame(15, fifteenDigitNegativeString.length());
    when(formEntryPrompt.getAnswerValue()).thenReturn(answerData);
    when(answerData.getValue()).thenReturn(fifteenDigitNegativeDouble);
    DecimalWidget decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
    assertThat(decimalWidget.getAnswerText(), is(equalTo(fifteenDigitNegativeString)));
    decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
    assertThat(decimalWidget.getAnswerText(), is(equalTo(fifteenDigitNegativeString)));
}
Also used : QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails) Test(org.junit.Test) GeneralStringWidgetTest(org.odk.collect.android.widgets.base.GeneralStringWidgetTest)

Example 8 with QuestionDetails

use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.

the class DecimalWidgetTest method negativeIntegerShouldDisplayNegativeWithNoDecimalPoint.

@Test
public // Fails when double is turned to string with toString or String.format(Locale.US, "%f", d)
void negativeIntegerShouldDisplayNegativeWithNoDecimalPoint() {
    Double negativeIntegerDouble = -999.;
    String negativeIntegerString = "-999";
    when(formEntryPrompt.getAnswerValue()).thenReturn(answerData);
    when(answerData.getValue()).thenReturn(negativeIntegerDouble);
    DecimalWidget decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
    assertThat(decimalWidget.getAnswerText(), is(equalTo(negativeIntegerString)));
    decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
    assertThat(decimalWidget.getAnswerText(), is(equalTo(negativeIntegerString)));
}
Also used : QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails) Test(org.junit.Test) GeneralStringWidgetTest(org.odk.collect.android.widgets.base.GeneralStringWidgetTest)

Example 9 with QuestionDetails

use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.

the class ExDecimalWidgetTest method digitsAboveLimitOfFifteenShouldBeTruncatedFromRight.

@Test
public // This should never be possible because the EditText has a limit on it
void digitsAboveLimitOfFifteenShouldBeTruncatedFromRight() {
    Double eighteenDigitDouble = 9999999999999994.;
    String fifteenDigitString = "999999999999994";
    assertSame(15, fifteenDigitString.length());
    when(formEntryPrompt.getAnswerValue()).thenReturn(answerData);
    when(answerData.getValue()).thenReturn(eighteenDigitDouble);
    ExDecimalWidget exDecimalWidget = new ExDecimalWidget(activity, new QuestionDetails(formEntryPrompt), new FakeWaitingForDataRegistry(), stringRequester);
    assertThat(exDecimalWidget.getAnswerText(), is(equalTo(fifteenDigitString)));
    exDecimalWidget = new ExDecimalWidget(activity, new QuestionDetails(formEntryPrompt), new FakeWaitingForDataRegistry(), stringRequester);
    assertThat(exDecimalWidget.getAnswerText(), is(equalTo(fifteenDigitString)));
}
Also used : FakeWaitingForDataRegistry(org.odk.collect.android.widgets.support.FakeWaitingForDataRegistry) QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails) GeneralExStringWidgetTest(org.odk.collect.android.widgets.base.GeneralExStringWidgetTest) Test(org.junit.Test)

Example 10 with QuestionDetails

use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.

the class DecimalWidgetTest method fifteenDigitDecimalValueShouldDisplayAllDigits.

@Test
public // precision for %f is 6
void fifteenDigitDecimalValueShouldDisplayAllDigits() {
    Double fifteenDigitDecimalDouble = 0.9999999999999;
    String fifteenDigitDecimalString = "0.9999999999999";
    assertSame(15, fifteenDigitDecimalString.length());
    when(formEntryPrompt.getAnswerValue()).thenReturn(answerData);
    when(answerData.getValue()).thenReturn(fifteenDigitDecimalDouble);
    DecimalWidget decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
    assertThat(decimalWidget.getAnswerText(), is(equalTo(fifteenDigitDecimalString)));
    decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
    assertThat(decimalWidget.getAnswerText(), is(equalTo(fifteenDigitDecimalString)));
}
Also used : QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails) Test(org.junit.Test) GeneralStringWidgetTest(org.odk.collect.android.widgets.base.GeneralStringWidgetTest)

Aggregations

QuestionDetails (org.odk.collect.android.formentry.questions.QuestionDetails)15 Test (org.junit.Test)9 GeneralStringWidgetTest (org.odk.collect.android.widgets.base.GeneralStringWidgetTest)7 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)3 MockFormEntryPromptBuilder (org.odk.collect.android.support.MockFormEntryPromptBuilder)3 NonNull (androidx.annotation.NonNull)2 IFormElement (org.javarosa.core.model.IFormElement)2 QuestionDef (org.javarosa.core.model.QuestionDef)2 DatePickerDialog (android.app.DatePickerDialog)1 DatePicker (android.widget.DatePicker)1 DateTime (org.joda.time.DateTime)1 LocalDateTime (org.joda.time.LocalDateTime)1 AudioButton (org.odk.collect.android.audio.AudioButton)1 StoragePathProvider (org.odk.collect.android.storage.StoragePathProvider)1 WidgetTestActivity (org.odk.collect.android.support.WidgetTestActivity)1 CameraUtils (org.odk.collect.android.utilities.CameraUtils)1 ExternalWebPageHelper (org.odk.collect.android.utilities.ExternalWebPageHelper)1 DateTimeWidget (org.odk.collect.android.widgets.DateTimeWidget)1 DateWidget (org.odk.collect.android.widgets.DateWidget)1 GeneralExStringWidgetTest (org.odk.collect.android.widgets.base.GeneralExStringWidgetTest)1