Real-World Math

Math is often not easy to learn, even for those of us who enjoy it. And if you don't use your mathematical knowledge, you just might forget how to use it. Danny Faught likes math and has found ways of using basic math like algebra, the modulo function, expected values, and logarithms in testing. It's kept his mind fresh on mathematical concepts and formulas, and he hopes it will do the same for you. In this week's column, he explains how to use math to improve testing.

Much of the math I learned in high school and college lies dormant. But when I sat down to come up with examples of using math skills on the job, I was surprised to find quite a few. I want to share some of the mathematical concepts I've used lately in real-world situations.

I was working with an organization with 200 developers and no testing specialists. They asked me to evaluate the feasibility of retraining some of the developers as testers, so we'd have a 4:1 ratio of developers to testers. I didn't think it was likely that that many of their developers would want to start focusing exclusively on testing, but I needed to figure out how many people would need to be retrained. While I could have used trial and error to guess the answer, I decided to put my rusty algebra skills to use instead.

I set up a system of equations, where T is the number of testers and D is the number of developers, after the retraining. First, this equation represents the 4:1 ratio:

          D = T * 4

And this equation represents the total number of people we have to work with:

          T + D = 200

Using substitution, I calculated the number of testers:

          T + D = 200
          T + T * 4 = 200
          T * 5 = 200
          T = 200 / 5
          T = 40

I could see that we would need 40 testers, leaving 160 as developers. I was excited to be able to use my high school algebra for something!

The Modulo Function
Remember calculating the remainder when doing division? For example, 25 ÷ 7 is 3 with a remainder of 4. The "modulo" function gives us the remainder, and it has some interesting applications. The symbol used in most programming languages for the modulo function is %, so to calculate the remainder of 25 ÷ 7, we would type 25 % 7, which gives us 4.

Here's a modulo example. I wrote a WebLoad script that logs in to a Web application. Many copies of the script may run at the same time, and each one needs to log in using a different account. I set up test users named testuser00000, testuser00001, etc. The traditional technique for doling out usernames in a load-test script is to put each username in a file and have each thread read one name from the file. But I prefer the more direct approach of generating the usernames without bothering with reading a file. Here's the Javascript code that does this for me in WebLoad:

wlLocals.userNum = ClientNum % wlGlobals.totalUsers

The script puts the value of wlLocals.userNum at the end of the string "testuser" to build the unique username, filling in leading zeros so the names would sort nicely in a database query. ClientNum is a built-in counter that starts at zero for the first thread and increments for each additional thread. (Note: ClientNum is not unique across multiple load generators, so this only works if you have a single load generator.)

When one thread finishes running the script, WebLoad starts another thread. For a long-running test, it's possible to use up all available test accounts. If that happens, I want it to loop back to the beginning of the list of users. That's where the modulo does its magic. I have the total number of users stored in the wlGlobals.totalUsers variable. So "ClientNum % wlGlobals.totalUsers" will cause the userNum to wrap back around to zero to avoid going outside the range of available user accounts.

Let's say we only


About the author

StickyMinds is a TechWell community.

Through conferences, training, consulting, and online resources, TechWell helps you develop and deliver great software every day.