zoukankan      html  css  js  c++  java
  • 软件测试第四周

    闰年测试

    • 仍在之前的等价类测试 testApp 上进行功能上的修改
    • 将正则表达式改为 [0-9]{1-4},不足之处在于非数字和负数都归为了同一类「非法输入」,有待改进
    • buttomPress 方法下先使用正则表达式判断函数判断输入是否合法,如果符合要求再进行下一步计算验证
    • 先算是否为世纪年(模 100),若是则模 400 判断是否闰年
    • 非世纪年则模 4 判断是否闰年,最后由 UIAlertView 显示判断结果弹窗

    测试用例

    编号 输入 输出
    1 2000 2000 是闰年
    2 1900 1900 不是闰年
    3 eadhwij 非法输入
    4 -100 非法输入

    测试截图

    
    
    //
    //  ViewController.m
    //  testApp
    //
    //  Created by trigger on 15/3/22.
    //  Copyright (c) 2015年 trigger. All rights reserved.
    //
    
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @property (strong, nonatomic) IBOutlet UITextField *textBoxText;
    - (IBAction)buttonPress:(id)sender;
    @end
    
    @implementation ViewController
    @synthesize textBoxText;
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        [self textCheckWithRegex:@""];
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    - (IBAction)buttonPress:(id)sender {
        NSString *message;
        
        if (![self textCheckWithRegex:textBoxText.text]) {
            message = @"非法输入";
        }else{
            int year = [textBoxText.text intValue];
            if (year % 100 == 0) {
                if (year % 400 == 0){
                    message = [[NSString alloc]initWithFormat:@"%d 是闰年", year];
                }else{
                    message = [[NSString alloc]initWithFormat:@"%d 不是闰年", year];
                }
            }else{
                if (year % 4 == 0) {
                    message = [[NSString alloc]initWithFormat:@"%d 是闰年", year];
                }else{
                    message = [[NSString alloc]initWithFormat:@"%d 不是闰年", year];
                }
    
            }
        }
       
        [[[UIAlertView alloc]initWithTitle:@"闰年检查" message:message delegate: nil cancelButtonTitle:@"好的" otherButtonTitles:nil, nil]show];
    }
    
    - (BOOL)textCheckWithRegex:(NSString*)str{
        NSString *searchText = [NSString stringWithString:str];
        NSError *error = NULL;
        NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[0-9]{1,4}" options:NSRegularExpressionCaseInsensitive error:&error];
        NSTextCheckingResult *result = [regex firstMatchInString:searchText options:0 range:NSMakeRange(0, [searchText length])];
        searchText = [searchText substringWithRange:result.range];
        if ([str isEqualToString:searchText] && ![str isEqualToString:@""]) {
            return true;
        }
        else{
            return false;
        }
    }
    
    @end
    
  • 相关阅读:
    Android Action Bar简介
    Android UX & UI 最佳实践: 设计有效的导航
    Android Design Principles
    Android 4.4 KitKat 新特性
    Android 尺寸单位转换和屏幕适配相关
    Android UI线程和非UI线程
    初探机器学习之使用百度EasyDL定制化模型
    初探机器学习之使用百度AI服务实现图片识别与相似图片
    初探机器学习之推荐系统的基础知识
    熊逸《唐诗50讲》壮心篇
  • 原文地址:https://www.cnblogs.com/triggerlin/p/4396586.html
Copyright © 2011-2022 走看看