如果输入从终端读取,如何在go-lang中测试代码

时间:2017-11-12 08:00:27

标签: testing go

我在golang中编写了一个代码,它从终端读取输入,然后在数组中反转该输入。我想为该函数编写一个测试。那么我如何为这类问题编写测试用例。

  

这是我正在运行的代码

-(void)suggestionsForCustomKeyboard:(NSString *)word{
    if ([currentString length] >= 1) {

    UITextChecker *textChecker = [[UITextChecker alloc] init];
    NSRange misspelledRange = [textChecker
                               rangeOfMisspelledWordInString:currentString
                               range:NSMakeRange(0, [currentString length])
                               startingAt:0
                               wrap:NO
                               language:@"en_US"];


    if (misspelledRange.location != NSNotFound) {

        guesses = [textChecker guessesForWordRange:misspelledRange
                                          inString:currentString
                                          language:@"en_US"];
        NSLog(@"First guess: %@", [guesses firstObject]);

    } else {
        NSLog(@"Textchecker Not found");
        autocorrectedText = @"";
    }

    if (arrPredectiveText.count >= 2){
        suggestionOne = [arrPredectiveText objectAtIndex:0];
        suggestionTwo = [arrPredectiveText objectAtIndex:1];
    }
    else if (arrPredectiveText.count == 1 && guesses.count >= 1) {
        suggestionOne = [arrPredectiveText firstObject];
        suggestionTwo = [guesses firstObject];
    }else if (arrPredectiveText.count == 0 && guesses.count > 0){
        suggestionOne = [guesses firstObject];
        if (guesses.count > 1) {
            suggestionTwo = [guesses objectAtIndex:1];
        }
    }

    NSLog(@"Textchecker all guess: %@", guesses);
    NSLog(@"Prediction: %@",arrPredectiveText);

}

这里我正在尝试编写像这样的测试函数

    <div *ngIf="AreThereMyOldMessages">
      <div *ngFor="let oldm of MyOldMessages;let i of MyOldMessages.length">
        <tr>
          <td>{{i}}<br>
            {{oldm.text}}
          </td>
        </tr>
      </div>
    </div>
    <div *ngIf="AreThereMyNewMessages">
      <div *ngFor="let message of MyNewMessages;let i of MyNewMessages.length">
        <tr>
          <td>{{i}}<br>
            {{message.text}}
          </td>
        </tr>
      </div>
    </div>
  </table>

这里的问题是我的反向功能不接受任何输入。我从终端读取输入,所以任何方式提供输入,以便测试用例正常工作

0 个答案:

没有答案