Be sure to look at the Blackboard Module for this week for various hand-in mechanisms!

C12 In Class Exercise: Test Design

Consider the following arbitrary code:

int32_t TestFunc(int32_t a, int32_t b, uint32_t x)
{ int32_t res;
  res = a * 2;
  if( b > 20) 
{ res = a+1; } else if((x == 7) || (a == 3))
{ res = a-100; } else if( (a < 10) && (b < 16)) { res = x+17; } else { res = 42; } return(res); }

Create unit test values to achieve the following objectives. For each unit test list the following in a row (bullet or table row as you prefer):
Test objective, a, b, x, res.
For example: MCDC1 a=99 b=99 x=99=> res=99

It is OK to divide up testing across the group, but everyone in the group should review the correctness of the tests before submitting the slide.

Supplemental Materials:

C13 In Class Exercise: Statechart Exercise

This is a GROUP exercise. Complete it using your ASSIGNED groups. Create a statechart for a maze-solving robot with the below properties. Be sure that your statechart has an initialization arc, a number of states, an action for each state, and guard conditions on each transition. It is OK to hand-draw the statechart and take a picture of it, or use any other convenient method that results in an acrobat file, a powerpoint file, or an image file (e.g., JPG).

Consider a maze-solving robot that uses the left-hand-rule approach to solving a maze. A person using this rule would extend their left hand and walk while keep it touching the wall at all times, turning as required to follow the wall.

However, our turtle-bot doesn't have a "left hand," and instead only has a front bumper. We assume that the front bumper can detect the wall without the need for the turtle bot to actually move (for example, it is a single forward-facing ultrasonic distance sensor with a range of less than one square size). Thus, implementing a left-hand-rule approach requires a step of turning left to see if the wall is there, and then either proceding or turning again depending upon whether the wall was sensed.

The turtle bot has the following movement capabilities. These are the ONLY permitted actuator outputs that can be set by states in the statechart. The system can only perform one action per time step, and can only be in one state per time step. (This is a fully synchronous state machine, with the time step equalling the time taken by the robot to turn or move, which we assume is the same for each possible action.)

The turtle bot has the following input sensing capabilities:

Solving a maze is subject to the following constraints:

  1. The maze is an NxM size rectangular grid, for example like a chessboard.
  2. You have no information as to where in the grid the turtle starts, and where in the grid the goal square is. (This means you have to book-keep movement and you can't exploit any knowledge about where the rest of the maze might be.)
  3. Each statechart transition takes one time step, including same-state default transitions.
  4. The turtle is only permitted to make exactly ONE of its listed movement capabilities at each time step. It should correctly process both input sources at each time step.
  5. Maze walls are between squares. This implies that each square is surrounded by 0, 1, 2, 3, or 4 walls. (If trapped inside 4 walls, movement is not possible.)
  6. The turtle displays movements in keeping with the left-hand-rule approach to maze solving.
  7. The turtle must stay still once it has reached the goal square

The output of this exercise should be a well formed statechart. Do NOT write code to implement the statechart. Paste the statchart onto a slide:

Here's a video showing how the turtle should move. (View directly on YouTube here: )

HW #10: Global Variables

(Be sure to list citations for references you use as a source for answers. If multiple references say the same thing, you need to only give one of them as a source.)

10-1. Consider a situation in which a variable is declared as a global (e.g., variables in the Project 2 student function starting code).

10-2. Look up the implementation for the min() function in the C library for a typical Unix system. (Hint: it's a macro -- find the macro definition. If it's not a macro, that's not the function you're looking for.)

10-3. Give one or two-sentence answers to the following questions:

Supplemental Material:

HW #11: Stack Overflow

No homework for this lecture.

Supplemental Materials: Lecture: Stack Overflow

HW #12: Unit Testing

Note: We teach cunit because it is more commonly supported on smaller embedded systems. For this homework you can use GUnit or other reasonable notation if you prefer. However, the course staff does NOT provide support for GUnit, so use at your own risk.

12-1. Two important concepts in black box testing are equivalence classes and boundary values. For this question consider an absolute value function:
int16_t abs16(int16_t i) { return (i < 0 ? -i : i); }

12-2. Consider testing the following code:

int16_t baz(int16_t a, int16_t b)
{ int16_t res = 0;
if((b < 6) && ((a < 27) || (b > 87) || (b == 52))) { res = b; } else { res = a; } return(res); }

12-3.Consider testing the following code:

int16_t bar(int16_t a, int16_t b)
{ int16_t res = 0;
if((a > 3) && (b < 112)) { if (a == 42)) { res = b; } else { res = a; } } else { res = a-b; if (a == 2 && b == 2) { res = a+b; } } return(res); }

Supplemental Material:

HW #13: Modal code and statecharts

13-1. Consider the maze-solving robot in the statechart class exercise from this week, shown above. That robot solved mazes using a left hand rule. Your team result might or might not have had a correct or clean solution in the limited time available in class. In this homework you'll get to try again ON YOUR OWN to create a statechart for a robot with the same rules EXCEPT you will create two variants: one with a left-hand-rule and one with a right-hand-rule maze solving heuristic. For the right-hand-rule turtle, the path taken to solve the maze shall be the path that would be taken by a person using their right hand to follow the maze wall until the goal is reached. While you obviously got ideas for maze solving from the class discussion, start with a clean sheet of paper (electronic or otherwise) for this homework, and make your own drawing yourself. If you missed lecture, it's OK to ask another student in class to show you their group's solution, but don't just copy it. The point of this homework is to make sure that you can do this on your own, without someone helping you. (I.e., did the knowledge from the class exercise actually stick?)

Follow these rules for your statechart:

13-2: Take a flowchart and convert it to a statechart

Supplemental Material: