Object-Oriented Programming Pre

by 17373260 彭毛小民

Outline

1. Test-Driven Development

2. SOLID——Open–closed principle

3. Date generater

4. Other Thinking

Topic

Test & Modify

TDD

TDD

My schedule for oop project:

  • Write a simple plan
  • Design Objects
  • Write some simple testcases and testcode
  • Write code
  • Rubber Duck Debugging
  • Run Testcase & Testcode

TDD

**合法字符**, Regex Form, set = `[ \\^\\t\\+-\\*\\dx]`

**若干空白字符**,Regex Form , ws = `[ \\t]*`  

**带符号整数**,Regex Form , num = `[+-]?\\d*`

**幂函数**,Regex Form, pow = `x(((ws)\\^(ws))(num))?`

**变量项**, Regex Form, term = `([+-]?)(ws)(\\d+(ws)\\*)(ws)(pow)`

**多项式的每一项**, Regex Form, poly = `[+-]?(ws)((term)|(num))`

Open–closed principle

  • Open For Extension
  • Closed For Modification

Test Env

  • using jar
  • using python / shell / c++ / java / ... 
  • using hand-made testcase

For jar

Without package:

With package:

Write a manifest like makefile...

Main-Class: Main
Main-Class: youpackage.Main
jar cvfm name.jar manifest *.class

Then

For generator

## 第一次作业testcode设计

### test 1
正则表达式的多次递归问题
参考`1.py`,`2.py`,多次构造含有相同border的字符串连续拼接
一个杀伤力版本应该是,在最后加入少许不合法情形。

### test 2
程序BigInteger的有效性,参考`testcode.cpp`,
随机构造任意长度的表达式格式化的输出到`ans`,合并判断。

### test 3
人工数据,对于几种不好判别的表达式进行解析

```
++ 1*x
+1*x^+1*x
+ 12 	 34*x
--x
```

### test4
tinycase攻击,制造一个输出为零的超多项的表达式`3.py`

### test5
通用攻击,采用随机生成数据

### output check
采用`sympy` package,微分命令
```python
from sympy.abc import x
str = input.replace("^","**");
ans = diff(eval(str))
```
可以直接比较两个多项式是否相等

Hand-made

  After discussed with your roommate/ classmate/ friend/ ... , you will find :

  1. some interesting testcases
  2. some modern & hackable tools
  3. forgot to hack someone, but enjoy design

QNS

1. The definition of coverage test ?

2. OOP or Java for beginners ?

 

OOP pre

By prime21

OOP pre

My oop class presentation

  • 964