@SmallTest
  public void testChoiceIterator() {
    final String inputText = "hello";
    final Bitmap bmp = TessBaseAPITest.getTextImage(inputText, 640, 480);

    // Attempt to initialize the API.
    final TessBaseAPI baseApi = new TessBaseAPI();
    baseApi.init(TessBaseAPITest.TESSBASE_PATH, TessBaseAPITest.DEFAULT_LANGUAGE);
    baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_LINE);
    baseApi.setVariable(TessBaseAPI.VAR_SAVE_BLOB_CHOICES, TessBaseAPI.VAR_TRUE);

    // Ensure that text is recognized.
    baseApi.setImage(bmp);
    String recognizedText = baseApi.getUTF8Text();
    assertTrue("No recognized text found.", recognizedText != null && !recognizedText.equals(""));

    // Iterate through the results.
    ResultIterator iterator = baseApi.getResultIterator();
    List<Pair<String, Double>> choicesAndConfidences;
    iterator.begin();
    do {
      choicesAndConfidences = iterator.getChoicesAndConfidence(PageIteratorLevel.RIL_SYMBOL);
      assertNotNull("Invalid result.", choicesAndConfidences);

      for (Pair<String, Double> choiceAndConfidence : choicesAndConfidences) {
        String choice = choiceAndConfidence.first;
        Double conf = choiceAndConfidence.second;
        assertTrue("No choice value found.", choice != null && !choice.equals(""));
        assertTrue("Found an incorrect confidence value.", conf >= 0 && conf <= 100);
      }
    } while (iterator.next(PageIteratorLevel.RIL_SYMBOL));
    iterator.delete();

    assertNotNull("No ChoiceIterator values found.", choicesAndConfidences);

    // Attempt to shut down the API.
    baseApi.end();
    bmp.recycle();
  }