Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Test Driven Development - a first example of principle in C

If you're writing a substantial chunk of code, chances are that you'll want to split it down into manageable pieces. By doing so, you can make for re-usable code, for clearer code when you come to maintain your application, and for code that you can test section by section.

I'm going to encourage yu to go a stage further, though - I'm going to encourage you to write the tests before you write the code, and have the tests form the specification. As the code grows, and functioanllity is added, you can add extra tests to your test pattern and by rerunning your tests each time you add to or alter the code, and then testing will make sure you've not damaged something else.

There are packages and fucntions to help you write your test driven development softwares, and unit testing stuff to let you separate your tests, and to manage the results. However, today I was teaching "Learning to program in C" and those extra routines use code that's far too sophisticted on day 1, so I wrote some simple stuff directly in C.

Code to be tested - [here]
Include file (headers) - [here]
Test code - [here]

You'll note that I've printed out results all through the tests, but then sent a final status out to stderr. That way I can run the tests in a verbose mode, but if I just want to see if it all works I can redirect stdout.

  trainee@kingston:~/c_dec14$ ./tdd
  Result is 24.54
  Result is 0
  Result is 56.82
  Result is 1
  Result is 18.08
  Result is -1
  WORKED
  trainee@kingston:~/c_dec14$ ./tdd > /dev/null
  WORKED
  trainee@kingston:~/c_dec14$


All of our courses emphasise excellent coding practise and advocate its application from early on - our course schedule is [here]. The example here is a very basic one, but we'll establish this principle at the start of your course and then make sure you write good, testable code for ever.
(written 2014-12-01)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
Q456 - Object Orientation and General technical topics - Test Driven Development and Behaviour Driven Development
  [4326] Learning to program - comments, documentation and test code - (2014-11-22)
  [4346] A behaviour driven example of writing a Java program - (2014-12-09)
  [4374] Test driven development, and class design, from first principles (using C++) - (2014-12-30)
  [4380] Behaviour Driven Development / Ruby and Cucumber - (2015-01-02)
  [4387] Regression Testing my website - Cucumber and Watir - (2015-01-07)
  [4457] Test framework for TCL - Tcltest - some examples - (2015-03-11)
  [4542] The principle of mocking - and the Python Mock package - (2015-10-17)
  [4634] Regression testing - via a very short C testing framework - (2016-01-29)
  [4652] Testing new algorithms in PHP - (2016-02-20)

C208 - C and C based languages - Programming techniques and tools
  [4341] Segmentation Fault, Segmentation Violation, Bus Error, Stack Smashing - (2014-12-04)


Back to
Flexible public courses - residential or commuting, programming newcomer or experienced, C or C++
Previous and next
or
Horse's mouth home
Forward to
Learning to program sample program - past its prime, but still useful
Some other Articles
Command line and file handling in C
Simple C structs - building up to full, dynamic example
Passing arrays into functions in C
Learning to program sample program - past its prime, but still useful
Test Driven Development - a first example of principle in C
Flexible public courses - residential or commuting, programming newcomer or experienced, C or C++
Splitting out code into name blocks for clarity and reusability
Misty Melksham Morning
First Java Application - calculating the weight of a tablecloth
Musings on a Welsh town
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.info/mouth/4336_Tes ... -in-C.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb