码迷,mamicode.com
首页 > 其他好文 > 详细

软件质量与测试第4周小组作业:WordCount优化

时间:2018-04-08 20:15:56      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:dev   uri   ann   测试报告   时间   use   设计   dash   access   

软件质量与测试第4周小组作业:WordCount优化

一、GitHub地址

https://github.com/fusidic/WC

二、PSP表格

PSP2.1 PSP阶段 预估耗时(分钟) 实际耗时(分钟)
Planning 计划 30 20
· Estimate · 估计这个任务需要多少时间 30 20
Development 开发 470 550
· Analysis · 需求分析 (包括学习新技术) 30 20
· Design Spec · 生成设计文档 20 20
· Design Review · 设计复审 (和同事审核设计文档) 30 20
· Coding Standard · 代码规范 (为目前的开发制定合适的规范) 30 30
· Design · 具体设计 30 40
· Coding · 具体编码 180 240
· Code Review · 代码复审 30 30
· Test · 测试(自我测试,修改代码,提交修改) 120 150
Reporting 报告 90 90
· Test Report · 测试报告 30 30
· Size Measurement · 计算工作量 30 30
· Postmortem & Process Improvement Plan · 事后总结, 并提出过程改进计划 30 30
合计 590 660

三.模块接口设计

处于任务分配的考量,我们小组将整个任务分成了输入控制 内容读取 分析核心 输出控制 几个功能模块,同时在组长17002的建议下,我们采用了Kotlin来进行模块的编写,因为Kotlin简洁,同时兼容Java,可以用Junit进行单元测试。

我负责的模块,主要完成文件及参数读取的功能,入口为ArgChecker类中的check函数

fun check(pindex: Int, pc: Int, msg: String): Boolean {
    if (pindex <= -1) return false
    if (pindex + 1 == pc) {
        throw IllegalArgumentException(msg)
    }

    return true
}

checkOutputArg()检验输入参数的合法性

fun checkOutputArg(oindex: Int, args: Array<String>): Boolean {
    val ofname = args[oindex + 1]
    if (Options.values().map { it.value }.contains(ofname)) {
        throw IllegalArgumentException("invalid output file name")
    }
    return true
}

对于不同参数功能的调用则放在了主函数中

for (value in Options.values()) {
    val index = args.indexOf(value.value)
    if (index == -1) {
        continue
    }
    when (value) {
        Options.C -> {
        checker.check(index, pc, "-c error")
        cc = CharCounter().count(ifile)
        }
        Options.W -> {
            checker.check(index, pc, "-w error")
            wc = WordCounter().count(ifile)
        }
        Options.L -> {
            checker.check(index, pc, "-l error")
            lc = LineCounter().count(ifile)
        }
        else -> {

        }
    }
}

文件的字数统计则简单的采用了Kotlin中的库函数file.readText().length

四、设计测试用例与测试

对于CharCounter(),使用了Junit对其进行了单元测试,测试的文本是某网页上的若干段文字(位于类CounterTest中),通过文本软件获得了测试文本的字符数,然后编辑其测试程序

package test.com.dashmrl.wc.counter

import com.dashmrl.wc.counter.CharCounter
import org.junit.Test
import java.io.File
import kotlin.test.assertEquals

/**
 * Author    fusidic
 * Time      10:25
 * Date      2018/4/8
 * Email     arithbar@gmail.com
 */
class CharCounterTest : CounterTest() {
    private val results = arrayOf(
            282,
            83,
            53,
            57,
            62,
            127,
            87,
            157,
            73,
            38,
            62,
            46,
            162,
            100,
            69,
            65,
            47,
            35,
            9,
            139
    )

    @Test
    fun count() {
        inputs.forEach {
            val c = CharCounter().count(createIntputFile(it, "input.txt"))
            assertEquals(results[inputs.indexOf(it)],c,"not equals,exit!!")
        }
    }
}

测试得到所有结果都与标准相符。

而对于参数输入的测试,因为参数的判断写在主函数中,在其他功能模块都完成了的情况下,ArgChecker的测试采用了黑盒测试的方法,通过bat脚本对其进行了黑盒测试。

wcPro.exe
wcPro.exe -c
wcPro.exe -w
wcPro.exe -l
wcPro.exe input.txt
wcPro.exe -c input.txt
wcPro.exe -w input.txt
wcPro.exe -l -o result.txt input.txt
wcPro.exe -c -w -l -o result.txt input.txt

以下列举某次测试的结果,对非法输入给出了警告:

PS C:\Users\Arith\Desktop> .\wcPro.exe -w
java.lang.IllegalArgumentException: no enough args!!
        at com.dashmrl.wc.WCKt.main(WC.kt:19)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.exe4j.runtime.LauncherEngine.launch(LauncherEngine.java:81)
        at com.exe4j.runtime.WinLauncher.main(WinLauncher.java:94)

五、小组贡献分

0.27

六、参考链接

http://www.cnblogs.com/ningjing-zhiyuan/p/8654132.html

邹欣 代码规范与代码复审

软件质量与测试第4周小组作业:WordCount优化

标签:dev   uri   ann   测试报告   时间   use   设计   dash   access   

原文地址:https://www.cnblogs.com/fisidic/p/8747029.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!