test for integers in R

as.integer(x, ...)
integer(length = 0)

integer creates a integer vector of the specified length. Each element of the vector is equal to 0.

as.integer attempts to coerce its argument to be of integer type. The answer will be NA unless the coercion succeeds.

is.integer returns TRUE or FALSE depending on whether its argument is of integer type or not,

The weird thing I find when I am trying to use is.integer is, is.integer(3) will return false.

so what happens?


Becaues is.integer shows the internal representation, which is not an
integer but a double (real number). Some functions create integer vectors,
for example the : notation:

> is.integer(1:10) [1] TRUE

Or, is.integer(as.integer(3)) will also return TURE

Note:  is.integer(x) does not test if x contains integer numbers! For that, use round, as in the function is.wholenumber(x) in the examples:

is.wholenumber <-
    function(x, tol = .Machine$double.eps^0.5)  abs(x - round(x)) < tol

To test if a R object contains only integers:






quality assurance的职位怎么样?_合集 mitbbs.com

Ans1: 1) it is harder to be a good QA
2) less control over the whole production process
3) probably always get a non-tech manager (both pro cand con)
4) sometimes less pay than development(not ncessary)

so, some people like to move out. usually the people who move out is above-avg since some other dept is willing to take them. the consequence is people who get left behind have to take more workload.


如果真的选择这个行业,建议以后朝performance testing or test automation frame work多发展,这2个方向都需要一定的编程能力,是manual testing无法作的,很多manager的职位,甚至developer manager都是从做这个的中间选出来的。


刚工作不久, 对于QA 的工作有很多疑惑, 不知哪位前辈能指点一下?

(1)我听说QA 有AUTOMATION QA , 可是目前我在一个小公司, QA TEAM 刚成立不久, 感觉AUTOMATION  方面不怎么样, 也就是用PERL 写写CODE, 能做一些简单的AUTOMATION, 比如, SUBMIT JOB, COMPARE RESULTS, 感觉应该有很多其他TOOL 可以用,不知其他QA 都用什么TOOL?
(2)没有受过关于QA 的任何培训(小公司), 不知从哪里可以找到QA 培训的材料, 课程, 可以学习一下。

(3) 关于QA 的CAEER PATH。怎样才能增加自己的VALUE, 使自己不容易别人代替?
(我觉得目前盼的活儿别人很容易就能取代我: 就是COLLECT TEST CASE, RUN REGRESSION, VERIFY TICKETS, 学一下 就能上手)

盼指点, 提前谢了!


some high level SDET can make >$180k a year. not to mention many company has “VP of product quality”…

【 在 windmaple (wind) 的大作中提到: 】
: 没啥职业前途,早点转吧

SDET的Career Path是什么?


1.SQA Analyst: 主要是manul testing,懂一点script或根本不懂。
2.SQA Engineer: 比SQA Analyst要高,要懂一些coding.
3.SDET/SET: MS是SDET,Google是SET.应该是绝大部分的工作focus在coding上。主要是做测试工具和自动化。其他公司很少这种职位。需要的coding比较好,算法比较好。基本上来说也就是developer了。只是在测试方面的developer.  SDET确实是最高的级别了。对SQA Analyst和SQAE来说的比较高级的automation的技术,对SDET来说是小儿科了。SDET有很多更深入的工作去做。

还有一些title,例如test developer,也差不多是SDET的意思。google的测试分两种,SQAE和SET,手工和自动测试的区别。微软现在可能只有SDET了。绝大部分公司最好的测试也就是SQAE.还有一种更高的title叫test architect. 现在市场上都没几个人能达到要求。





【 在 shah (-1) 的大作中提到: 】
: 我看了微软一个员工得blog,抱怨他做sdet得时候还是受歧视的,最后
: 还是设法转到sde了

美国it公司分档_from mitbbs.com

第一档次: Dropbox, Square, Pinterest, Facebook, LinkedIn, Google, Twitter,
: Apple
: 第二档次: Zynga, Yelp, Netflix, Skype, VMWare, Salesforce, Groupon, Paypal
: Evernote, Box.net, Quora, A9.com, 126Lab, Yammer, Jive, Wikimedia,
: Craigslist
: 第三档次: Oracle, EMC, eBay, Intuit, NetApp, NetSuite, Yahoo, Adobe,
: Autodesk, Symantec, Riverbed, Quantcast, Concur, Aster Data, Citrix, EA等

算上湾区以外公司, Amazon, Micriosoft可以排在第二档次
Expedia, RedHat, RackSpace, Akamai, Bloomberg等可以排在第三档次


What is spinlock, Peterson’s algorithm,Semaphore (programming),Dining philosophers problem, paging, etc





http://enos.itcollege.ee/~jpoial/docs/tutorial/essential/threads/deadlock.html starvation and deadlock




What is fragmentation? Different types of fragmentation? – Fragmentation occurs in a dynamic memory allocation system when many of the free blocks are too small to satisfy any request. External Fragmentation: External Fragmentation happens when a dynamic memory allocation algorithm allocates some memory and a small piece is left over that cannot be effectively used. If too much external fragmentation occurs, the amount of usable memory is drastically reduced. Total memory space exists to satisfy a request, but it is not contiguous.Internal Fragmentation: Internal fragmentation is the space wasted inside of allocated memory blocks because of restriction on the allowed sizes of allocated blocks. Allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used

What is a Safe State and what is its use in deadlock avoidance? – When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state. System is in safe state if there exists a safe sequence of all processes. Deadlock Avoidance: ensure that a system will never enter an unsafe state.

What is CPU Scheduler? – Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them. CPU scheduling decisions may take place when a process: 1.Switches from running to waiting state. 2.Switches from running to ready state. 3.Switches from waiting to ready. 4.Terminates. Scheduling under 1 and 4 is non-preemptive. All other scheduling is preemptive.


When paging is used, a problem called “thrashing” can occur, in which the computer spends an unsuitable amount of time swapping pages to and from a backing store, hence slowing down useful work. Adding real memory is the simplest response, but improving application design, scheduling, and memory usage can help.

Journaling file system


System development life cycle_SDLC

Not every project will require that the phases be sequentially executed. However, the phases are interdependent. Depending upon the size and complexity of the project, phases may be combined or may overlap.[7]


The SDLC is a process used by a systems analyst to develop an information system, training, and user (stakeholder) ownership. Any SDLC should result in a high quality system that meets or exceeds customer expectations, reaches completion within time and cost estimates, works effectively and efficiently in the current and planned Information Technology infrastructure, and is inexpensive to maintain and cost-effective to enhance.[2] Computer systems are complex and often (especially with the recent rise of service-oriented architecture) link multiple traditional systems potentially supplied by different software vendors. To manage this level of complexity, a number of SDLC models or methodologies have been created, such as “waterfall“; “spiral“; “Agile software development“; “rapid prototyping“; “incremental“; and “synchronize and stabilize”.[3]….


From Wikepedia

The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTMLXHTML and XMLdocuments.[1] Objects in the DOM tree may be addressed and manipulated by using methods on the objects. The public interface of a DOM is specified in its application programming interface (API).



The World Wide Web Consortium (W3C), founded in 1994 to promote open standards for the World Wide Web, brought Netscape Communications and Microsoft together with other companies to develop a standard for browser scripting languages, called “ECMAScript“. The first version of the standard was published in 1997. Subsequent releases of JavaScript and JScript would implement the ECMAScript standard for greater cross-browser compatibility.

After the release of ECMAScript, W3C began work on a standardized DOM. The initial DOM standard, known as “DOM Level 1,” was recommended by W3C in late 1998. About the same time, Internet Explorer 5.0 shipped with limited support for DOM Level 1. DOM Level 1 provided a complete model for an entire HTML or XML document, including means to change any portion of the document. Non-conformant browsers such as Internet Explorer 4.x and Netscape 4.x were still widely used as late as 2000.

DOM Level 2 was published in late 2000. It introduced the “getElementById” function as well as an event model and support for XML namespaces and CSS. DOM Level 3, the current release of the DOM specification, published in April 2004, added support for XPathand keyboard event handling, as well as an interface for serializing documents as XML.

By 2005, large parts of W3C DOM were well-supported by common ECMAScript-enabled browsers, including Microsoft Internet Explorer version 6 (2001)OperaSafari and Gecko-based browsers (like MozillaFirefoxSeaMonkey and Camino).


Web browsers

This section may require copy editing for grammar, style, cohesion, tone, or spelling. You can assist by editing it(September 2011)

Web browsers usually use an internal model similar to the DOM in order to render a document (such as an HTML page). The DOM APIs are also used to inspect or modify a Web page from JavaScript code. In other words, the Document Object Model is the way JavaScript sees the browser state and the HTML page it contains.

When an HTML page is rendered in a browser, the browser parses the markup (e.g. HTML), downloaded from the web-server into an in-memory DOM. The DOM is used to construct additional internal structures used to display the page in the browser window.

The nodes of every document are organized in a tree structure, called the DOM tree. The topmost node in the DOM tree is theDocument object. Each node has zero or more children.

An example of a DOM tree is shown below:

 |-> Document
   |-> Element (<html>)
     |-> Element (<body>)
       |-> Element (<div>)
         |-> text node
         |-> Anchor
           |-> text node
       |-> Form
            |-> Text-box
            |-> Text Area
            |-> Radio Button
            |-> Check Box
            |-> Select
            |-> Button


Because DOM supports navigation in any direction (e.g., parent and previous sibling) and allows for arbitrary modifications, an implementation must at least buffer the document that has been read so far (or some parsed form of it).[citation needed]

[edit]Layout engines

Web browsers rely on layout engines to parse HTML into a DOM. Some layout engines such as Trident/MSHTML and Presto are associated primarily or exclusively with a particular browser such as Internet Explorer and Opera respectively. Others, such as WebKitand Gecko, are shared by a number of browsers, such as Google ChromeFirefox and Safari. The different layout engines implement the DOM standards to varying degrees of compliance.

Static methods in Class

When should we use static methods in class?

One rule-of-thumb: ask yourself “does it make sense to call this method, even if no Obj has been constructed yet?” If so, it should definitely be static.

So in a class Car you might have a method double convertMpgToKpl(double mpg) which would be static, because one might want to know what 35mpg converts to, even if nobody has ever built a Car. But void setMileage(double mpg) (which sets the efficiency of one particular Car) can’t be static since it’s inconceivable to call the method before any Car has been constructed.

(Btw, the converse isn’t always true: you might sometimes have a method which involves two Car objects, and still want it to be static. E.g. Car theMoreEfficientOf( Car c1, Car c2 ). Although this could be converted to a non-static version, some would argue that since there isn’t a “privileged” choice of which Car is more important, you shouldn’t force a caller to choose one Car as the object you’ll invoke the method on. This situation accounts for a fairly small fraction of all static methods, though.)

Define static methods in the following scenarios only:

  1. If you are writing utility classes and they and they are not supposed to be changed.
  2. If the method is not using any instance variable.
  3. If any operation is not dependent on instance creation.
  4. If there is some code that can easily be shared by all the instance methods, extract that code into a static method.
  5. If you are sure that the definition of the method will never be changed or overridden. As static methods can not be overridden.

In general, if your situation requires encapsulation of state or an organizational structure, then you will be using classes.

On the other hand, if you have something that is a cross-cutting concern, and can be used broadly across your application, you might consider methods in a static utility class. System.Math in the .NET framework (and Java) is an example of this.


I’m refactoring some code and I’m looking at a class called HFile. HFile has all private constructors so that you can actually create instances of it. Instead of creating instances of HFiles as follow:

var file = new HFile('filename') file.Save() 

All HFile interaction is handled via static methods. So if I wanted to save a file I would call:


and then internally an instance of HFile would be created and then saved. Obviously without knowing the whole story any reader must reserve judgment, but it seems like using static methods has become very fashionable at my place of work. So I’m wondering if there are good principles/best practices for usage of static methods that can helpful for a group of guys sitting down and reviewing their usage of static methods.


In your example, HFile is probably an object with state, so I would not generally use a static method to save it. It’s simpler just to make a method call on the specific HFile object, rather than having to pass the entire object to a static method for saving. Whether that makes sense or not in your particular application depends on whether your application’s paradigm sees HFile objects as things to be passed around and acted on by outside methods, or as standalone objects capable of saving themselves.

After reading Misko’s articles I believe that static methods are bad from a testing point of view. You should havefactories instead(maybe using a dependency injection tool like Guice).

how do I ensure that I only have one of something

only have one of something The problem of “how do I ensure that I only have one of something” is nicely sidestepped. You instantiate only a single ApplicationFactory in your main, and as a result, you only instantiate a single instance of all of your singletons.

The basic issue with static methods is they are procedural code

The basic issue with static methods is they are procedural code. I have no idea how to unit-test procedural code. Unit-testing assumes that I can instantiate a piece of my application in isolation. During the instantiation I wire the dependencies with mocks/friendlies which replace the real dependencies. With procedural programing there is nothing to “wire” since there are no objects, the code and data are separate.

An article worthy of reading: Static Methods are Death to Testability

Curiously recurring template pattern(CRTP)


” The curiously recurring template pattern (CRTP) is a C++ idiom in which a class X derives from a class template instantiation using X itself as template argument.[1]

how to use CRTP to achieve independent variables for static variables defined in a base class:



Effective C++ : Copy all parts of an object

1. If you add a data member to a class, you need to make sure that you update all the constructors as well as any nonstandard forms of operator= in the class, if you forget, compilers are unlikely to remind you.

2. Any time you take it upon yourself to write copying functions for a derived class, you must take care to also copy the base class parts. Those parts are typically private, of course (see Item 22), so you can’t access them directly.  Instead, derived class copying functions must invoke their corresponding base class functions.

3. Don’t try to implement one of the copying functions in terms of the other. Instead, put common functionality in a third function that both call.

an example given in the book to illustrate 2nd point  is:

void logCall (const std: string & funcName); //make a log entry

class Customer{


Customer (const Customer & rhs) ;

Customer & operator =( const Customer & rhs);


std:string namee;


class PriorityCustomer : public Customer {     // a derived class


PriorityCustomer( const PriorityCustomer & rhs);

PriorityCustomer & operator= (const PriorityCustomer & rhs);


int priority;



The correct way to the two copy functions in PriorityCustomer class is:


PriorityCustomer(const PriorityCustomer & rhs): Customer (rhs),  //invoke base class copy ctor



logCall (“PriorityCustomer copy constructor”);



PriorityCustomer &  PriorityCustomer:: operator=(const PriorityCustomer & rhs)


logCall( “PriorityCustomer copy assignment operator”);

Customer::operator= (rhs); //assign base class parts

priority =rhs.priority;

return * this;


Head first design pattern: Observer

The Observer Patterndefines a one-to-many dependency between objects so that when one object changes state, all of its dependents are
notified and updated automatically.

Even though the java have builti-in support for observer pattern, with Observable, and Observer, sometimes we still have to roll our own implementation.

Note: shortcomings of built-in Observable in Java:

violate our OO design principle of programming to interfaces not  implementations. Observable is a class, and we have to subclass it. as we know, a class that already extends another superclass won’t be able to sublcass Observable.

2nd principle violated : favor composition over inheritance. Why?  Observable protects crucial methods: the setChanged() method is protected. This means you can call setChanged()  only if you’ve subclassed Observable. This means you can’t even create an instance of the Observable class and compose it with your own objects, you have to subclass.

Note: Design Principle III:

Strive for loosely coupled designs  between objects that interact.


How to use Java’s Observer Pattern:

For an object to become an observer, as usual, implements the observer interface (this time the java.util.Observer interface) and call addObserver() on any Observable object. Likewise, to remove yourself as an observer just call deleteObserver().

For the Observable to send notification. First of all you need to be Observable by extending the java.util.Observable
superclass. From there it is a two step process: 1. You first must call the setChanged() method to signify that the state has changed in your object.

2 .Then, call one of two notifyObservers() method:   either notifyObservers() , which means  we’re using the PULL model;  or notifyObservers(Object arg), correspondng to PUSH model

Head first design pattern (1) Strategy pattern

What I have learned in the first chapter:

Design principle (1) : Separate what varies from what not vary

(2) program to interface, instead of implementation

(3) Favor composition over inheritance: time spent after development, like maintaining and extension costs more time than developing itself. Thus we should not emphasize reuse over maintainability and extensibility. Composition is a better way to achieve code reuse because it is a better compromise between code reuse and maintainability. Another problem with inheritance not mentioned in this textbook, as it is not related with design pattern, is diamond problem, which is talked about in another article posted in my blog (copied from wikepedia)

The Strategy  pattern used in the first example, SimuDuck, is defined as:  “The strategy pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.”

The set of class that implements the interface “flybehavior”, “quackbehavior”, is a set of algorithm encapsulated.

Most patterns and principles address issues of change in software.

Most patterns allow some part of a system to vary independently of all other parts.