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的更多相关文章

  1. Cracking the coding interview 第一章问题及解答

    Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...

  2. 《Cracking the Coding Interview》读书笔记

    <Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...

  3. Cracking the coding interview

    写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...

  4. Cracking the coding interview目录及资料收集

    前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...

  5. Cracking the Coding Interview(Trees and Graphs)

    Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...

  6. 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 ...

  7. 《Cracking the Coding Interview》——第12章:测试——题目6

    2014-04-25 00:53 题目:你要如何测试一个分布式银行系统的ATM机? 解法:ATM是Automatic Teller Machine,取钱的.我想了半天,没找到什么很清晰的思路,也许是因 ...

  8. 《Cracking the Coding Interview》——第12章:测试——题目5·

    2014-04-25 00:41 题目:怎么测试一支笔?(Pen?您老说的是钢笔?) 解法:这种简约而不简单的题目,实在是面试官最喜欢,面试者最头疼的类型了.面试官可以只花三秒,以一种灰常高贵冷艳的语 ...

  9. 《Cracking the Coding Interview》——第12章:测试——题目4

    2014-04-25 00:35 题目:没有专门的测试工具,你要如何对一个网页进行压力测试? 解法:拼手速,拼电脑数量呗.快捷键+复制粘贴网址,狂搞一番.话说回来,有脚本语言的情况下,直接写个脚本来模 ...

随机推荐

  1. IIS7 http自动跳转到https(通过编辑Web.config实现)

    本文摘自:https://www.cnblogs.com/wxbug/p/7054972.html 1.下载安装URL重写模块:Microsoft URL Rewrite Module 32位:htt ...

  2. gcc常用参数列举

    [参数详解] -c    只激活预处理,编译,和汇编,也就是他只把程序做成obj文件  例子用法:  gcc -c hello.c  他将生成.o的obj文件    -S  只激活预处理和编译,就是指 ...

  3. 特殊矩阵的压缩存储(转自chunlanse2014)

    对称矩阵 对于一个矩阵结构显然用一个二维数组来表示是非常恰当的,但在有些情况下,比如常见的一些特殊矩阵,如三角矩阵.对称矩阵.带状矩阵.稀疏矩阵等,从节约存储空间的角度考虑,这种存储是不太合适的.下面 ...

  4. S/4HANA for Customer Management里的搜索分页处理

    这篇文章的英文版我发在了SAP Community上:Paging Implementation in S/4HANA for Customer Management https://blogs.sa ...

  5. Excel公式巧用-将新值替换旧值,新值为空保留原值

    使用excel时候遇到 将新值替换旧值,新值为空保留原值的问题,简单使用Excel的函数即可以实现.

  6. [转载]开启debug调试模式

    debug+trace模式可以查看开发过程中TP的错误信息,可以更好地帮助开发者debug.但是debug模式的开启还不是简单的在配置文件中中设置就可以的,经过查资料摸索,找到一种有效的方法. 首先在 ...

  7. jmeter参数化读取数据进行多次运行

    jmeter参数化数据,可以使用csv,还可以使用数据库的方式 1.使用csv读取数据 在线程组中,配置原件中,选择csv data set config 1.本地创建了16个数据,存为test.tx ...

  8. poj 3485 区间选点

    题目链接:http://poj.org/problem?id=3485 题意:X轴上公路从0到L,X轴上下有一些点给出坐标代表村庄,问在公路上最少建几个出口才能使每个村庄到出口的距离不超过D. 以村庄 ...

  9. .nettiers和SQLite搅合到一块之后遇到的问题

    第一步 用SQLiteStudio生成一个新的数据库,sqlitetest,新建一张表test,建立一个主键字段ID,一个字符字段Name,建立完成,留待后用. 第二步 用VS2010建立一个sqli ...

  10. matlab vs联调

    vs 和matlab联调,最近真的把我搞挂了要. 首先,怎么进入联调呢.在vs里先设置一下. vs:tools->attach to process,选择matlab,注意此时matlab一定是 ...