《Cracking the Coding Interview》——第12章:测试——题目3
2014-04-24 23:28
题目:玩象棋游戏,你要设计一个bool型的方法来检测一个棋子能否移动到指定位置。
解法:不同的棋子有不同的移动规则,那么应该采取棋子基类实现接口,各个棋子子类来实现的方式。棋子除了类型之外,还必须要记录当前位置,作为判断的依据。而要移到的位置,则作为参数传给方法。不过这个题目出现在软件测试的章节里,应该是要描述如何测试吧。没学过系统的测试方法,遇到这种题的话还真没办法。
代码:
// 12.3 You're testing a method canMoveTo(int x, int y), which is a member method of a class Piece. Piece represents a piece in the chess game. How would you perform the testing?
// Answer:
// 1. Apparently every kind of pieces in chess has its own rule of moving. So the class Piece must be an abstract class, which will inherited by various kinds of specific pieces.
// 2. You always have to check if (x, y) is out of border. So this will be included in base class Piece.
// 3. Every piece has its own rule of moving, so the derived class will have to implement its own rule(), which will be executed by canMoveTo().
// 4. The class Piece should look like this:
// 5. The base class will have an interface named rule(), which will be implemented by derived class.
class Piece {
public:
virtual bool canMoveTo(int x, int y);
private:
// ...
virtual bool rule(int x, int y) = ;
};
// 6. Thus, the test should cover two parts:
// 6.a. The coordinates (x, y) will cover in-bound and out-of-bound cases.
// 6.b. Every rule() function will be executed inside canMoveTo(), thus the test will also be included here.
《Cracking the Coding Interview》——第12章:测试——题目3的更多相关文章
- Cracking the coding interview 第一章问题及解答
Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...
- 《Cracking the Coding Interview》读书笔记
<Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...
- Cracking the coding interview
写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...
- Cracking the coding interview目录及资料收集
前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...
- Cracking the Coding Interview(Trees and Graphs)
Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...
- Cracking the Coding Interview(Stacks and Queues)
Cracking the Coding Interview(Stacks and Queues) 1.Describe how you could use a single array to impl ...
- 《Cracking the Coding Interview》——第12章:测试——题目6
2014-04-25 00:53 题目:你要如何测试一个分布式银行系统的ATM机? 解法:ATM是Automatic Teller Machine,取钱的.我想了半天,没找到什么很清晰的思路,也许是因 ...
- 《Cracking the Coding Interview》——第12章:测试——题目5·
2014-04-25 00:41 题目:怎么测试一支笔?(Pen?您老说的是钢笔?) 解法:这种简约而不简单的题目,实在是面试官最喜欢,面试者最头疼的类型了.面试官可以只花三秒,以一种灰常高贵冷艳的语 ...
- 《Cracking the Coding Interview》——第12章:测试——题目4
2014-04-25 00:35 题目:没有专门的测试工具,你要如何对一个网页进行压力测试? 解法:拼手速,拼电脑数量呗.快捷键+复制粘贴网址,狂搞一番.话说回来,有脚本语言的情况下,直接写个脚本来模 ...
随机推荐
- 【js基础修炼之路】- 微任务,宏任务和Event-Loop
一段代码让你了解Event-Loop console.log(1); setTimeout(() => { console.log(2); }, 0); new Promise((resolve ...
- DOM笔记(十二):又谈原型对象
因为之前谢过一篇关于原型对象的笔记:浅谈JavaScript中的原型模式.现在我又重新看到这个话题,对原型有了进一步的理解,所以,又要谈谈原型对象. 一.理解原型对象 创建的每一个函数都有一个prot ...
- 计算多项式Poj(1996)
题目链接:http://poj.org/problem?id=1996 思路: 刚开始打了个二维表,调了一个小时,爆内存了. #include <stdio.h> #include < ...
- DOM(四):h5扩展方法
getElementByClassName()方法getElementByClassName()方法接收一个参数,即一个包含一或多个类名的字符串,返回带有指定类的所有元素的NodeList //取得所 ...
- ios各层
数据持久层.业务逻辑层.表示层 数据持久层: 持久化(Persistence)意思就是当你退出app的时候它还会存在. dao层:DAO (Data Access Object) 数据访问对象是一个面 ...
- Node.js 的初体验
例子1: 1.首先第一步 :要 下载 node.js. 官网 上可以下载 下载完后,是这个玩意. 2. 打开 node.js ,然后输入 // 引入http模块 var http = require( ...
- python—命名空间、作用域查找顺序、闭包
名称空间 name space,如下图: x = 1, 1存放在内存中,1 会有一个内存地址,x 则 存放在 name space 里,并同时记录了 1的内存地址, 即 名称空间是存放了变量x与1绑定 ...
- view的superview的变换
今天遇到一个奇怪的问题,一个view(称为subview)被加在了一个cell(superView1)上,然后创建了一个view(为superView2),将subview重新加在了superView ...
- textkit
更详细的内容可以参考官方文档 <Text Programming Guide for iOS>. “Text Kit指的是UIKit框架中用于提供高质量排版服务的一些类和协议,它让程序能够 ...
- (转)Unity 和 Cocos2d-x 越渐流行,国内公司开发「自研游戏引擎」的意义何在?
分几个角度来说:一.我认为,Unity3D将无可挽回的,或者说,势在必得的,成为接下来很多年内,世界移动领域游戏引擎市场霸主.回顾历史,正如同咱们经历过一次又一次的互联网时代变革一样,x86,wind ...