Why Unit Test?

Contrary to popular belief, the purpose of unit tests is not to verify correctness of code. Correctness can only be determined by a human. Code can be beautifully engineered and thoroughly unit tested, yet incorrect. The purpose of unit testing is more nuanced: to prevent changes to the expected behavior. When we write unit tests, we are formally specifying the expected behaviors of the testSubject. Whether of not these expectations are the correct expectations is purely subjective. When all of the expected behavior of our code is being witnessed by unit tests, we have a ‘safety net’ in place that allows us to […]


Test Driven Development (TDD) Tutorial

Introduction: Kent Beck, one of the original signers of the Agile manifesto and creator of eXtreme Programming, is credited with discovering Test Driven Development (TDD), but he claims he merely re-popularized the technique and coined the term. Here is what he had to say about rediscovering the technique: “The original description of TDD was in an ancient book about programming. It said you take the input tape, manually type in the output tape you expect, then program until the actual output tape matches the expected output. After I’d written the first xUnit framework in Smalltalk I remembered reading this and […]

Code Java

Answering an Interview Question…Thoroughly

Here is a coding exercise I was asked to solve during a recent interview: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, … By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. This is a basic solution, it is what I consider a rough prototype. /* Each new term in the Fibonacci sequence is generated by adding the previous two terms. By […]


Zoomable UITableView iOS component

Apple’s UITableView component does has many clever features right out of the box, but the ability to pinch zoom is not one of them.  I’ve created a custom subclass of UITableView that adds a pinch zoom gesture.  Check out the example project on Github:

Code iOS

iOS Fix: file is universal (2 slices) but does not contain a(n) armv7s slice: /path/to/file for architecture armv7s

This common error plagued be when trying to run my weatherApp on an iOS device.  It turns out that a build setting needs to be changed. In xcode, select your project file. select the ‘Build Settings’ tab change the view from ‘Basic’ to ‘All’ search for ‘Build Active Architecture Only’ set this value to YES.

C Circuits

Reverse engineering a 16 character display using an Atmel 328p.

Recently I wanted to expand the functionality of an automated test harness for an embedded device. The device has a 16 character display made of 4 Avago HDLx-2416 Series parts (datasheet). I gutted the device and tapped the display’s pins to my AVR. The AVR reads the LED display’s signal pins and sends the displayed string to the test harness via serial connection. Now the test harness can verify that the device under test’s display is lighting as expected. /* * ScreenScan.cpp * * Created: 6/8/2012 *  Author: BK Turley */ /* port wiring: PB0 – ascii 0 PB1 – […]

C Circuits

Switches and interrupts on a PSoC 1 Microcontroller

I. Introduction / Summary The most practical way for a microcontroller to retrieve input is via interrupt.  The vast majority of modern processors have interrupt functionality.  This functionality allows a processor to work on background tasks while no input has happened. Once input is detected, the processor diverts its attention to react, then returns to where it left off after the interrupt has been serviced. II. Description and Circuit Diagrams An optical encoder is connected to VCC and ground to provide power to its internal emitters, detectors, and squaring circuitry.  The encoders outputs are connected to P1[4] and P1[5] on […]


Polling a switch Using a PSoC 1 Microcontroller

     One way for a microcontroller to retrieve input is known as polling.  Polling means repeatedly measuring  a sensors value.  I will describe how to poll a pushbutton switch  and react to its measurement when using a Psoc3 microcontroller.   /* * Filename: switchpolling.c * * Title: Polling a switch with a Psoc microcontroller * * Description: This source code file is used with a Psoc 3 microcontroller to poll a switch. * Upon detecting a change in the switches state, An LCD is updated to display the number of * times the switch has been closed in Hex […]


Simple Multi-threaded web server written in C using pthreads

This Multi-threaded web server takes advantage of the posix thread library to enable it it serve multiple files at the same time.  Compile using gcc and run on a linux server. // Multi-Threaded web server using posix pthreads // BK Turley 2011 //this simple web server is capible of serving simple html, jpg, gif & text files //—– Include files ——————————————————— #include <stdio.h> // for printf() #include <stdlib.h> // for exit() #include <string.h> // for strcpy(),strerror() and strlen() #include <fcntl.h> // for file i/o constants #include <sys/stat.h> // for file i/o constants #include <errno.h> /* FOR BSD UNIX/LINUX —————————————————- */ […]