21 April 2017

Algorithm to Find All Divisors of BigInteger

I was working on one of the math programming challenges from Project Euler recently and needed to implement an algorithm to find all of the divisors of a BigInteger.

A bad brute-force approach would be to visit all values from 1 to N and see which ones divide evenly into N.

A better approach would be to just check all values from 1 to the square root of N. Any values found that divide evenly into N will also give another divisor, since if we have value i then we can find j = N / i where i <= j

But the Java API for BigInteger does not include a calculation of its square root. And I don't want to write an algorithm to calculate the square root today. This algorithm, however, is almost as efficient as one limited by the square root:

13 April 2017

STAMP: The 5 Elements of Writing Automated UI Tests

What are the common elements for writing and running automated UI-driven functional tests?

I am a software developer, not a QA tester, so my interest is in writing some form of scripts to perform tests through a user interface; I am not into tools that record a user's UI interaction.

The question arose recently, while I sat through an introduction to the custom-built testing framework of a project I am working on. (first, a clarification: by "framework" for this article I mean the custom code that a development team needs to create in order for the automated testing system to interact in a meaningful way with the production code. I do not intend it to refer to the testing platform itself. I'll call a tool like jUnit or Selenium a tool or a platform, and the set of tests, test doubles, and other artefacts of testing a specific system I will call the Framework.)

My guide for the learning session had a tendency to do deep-dives into the low-level details. After several minutes, I pulled us into a higher-level discussion, so that I could map the home-brewed implementation to concepts I had already used on several previous projects.

I would suggest that there are at least 5 common elements that any functional testing framework will require of the devs who write tests and expand the framework. Since my Preaching class (see my bio!) taught me to work in memory hooks, I'll spell the acronym "STAMP":

  1. S - Scripting: some way to define a sequence of actions
  2. T - Test Cases: the ability to define and differentiate any number of different test scenarios
  3. A - Asserting: an ability to compare an expected state or condition against the actual state or condition
  4. M - Mapping: an association between the screen elements and the test framework
  5. P - Persistence: a means of defining and injecting data with which the UI will interact, since UI state and functional behaviour will often depend on some notion of persistence