Kollego
← Full Engineering module guide

TestAS · Engineering

Computer science: TestAS practice testlets

Following an algorithm or a flow of logical steps and saying what it outputs.

testas.de lists this topic for the Engineering module. In the test it comes as testlets: a short text, table or formula, then 4 to 8 questions you answer from it.

Topic list: testas.de

Two practice testlets

Full exam-length testlets from the Kollego course, generated the same way as our mocks. Answer from the material, then open each answer to check.

Testlet 1

Logic gates in an alarm system

Digital circuits process signals that have only two states, represented as 1 (true, high voltage) and 0 (false, low voltage). Logic gates combine input signals according to simple rules. An AND gate outputs 1 only if all its inputs are 1. An OR gate outputs 1 if at least one input is 1. A NOT gate, or inverter, reverses its single input. A NAND gate is an AND gate followed by NOT: it outputs 0 only if all inputs are 1. A NOR gate outputs 1 only if all inputs are 0. An exclusive OR (XOR) gate outputs 1 if exactly one of its two inputs is 1.

AND: A·B OR: A + B NOT: Ā XOR: 1 if A ≠ B

The behaviour of a gate or a network of gates is described by a truth table, which lists the output for every combination of inputs. With n inputs, there are 2 to the power of n combinations. Networks are evaluated step by step, working from the inputs towards the output and noting the value at each intermediate point.

NAND and NOR gates are called universal, because any other logic function can be built from them alone; chip manufacturers therefore often use them as basic building blocks. Logic networks are found in control systems, safety interlocks and, in vast numbers, in computer processors.

Logic expressions can be simplified with Boolean algebra, which reduces the number of gates needed. For example, A·B + A·B̄ simplifies to A, since the output then depends only on A.

In practice, engineers also consider what happens if a sensor fails: alarm inputs are often wired so that a broken wire is treated like an open door.

A security company designs the control logic for a building alarm. There are four input signals: D = 1 when a door is open, W = 1 when a window is open, A = 1 when the system is armed, and P = 1 when the panic button is pressed. The siren S is controlled by the network below. It first combines the door and window signals with an OR gate, then combines the result with the armed signal in an AND gate, and finally combines this with the panic button in a second OR gate.

Alarm network
StageGateInputsOutput
1ORD, WX
2ANDX, AY
3ORY, PS (siren)
  1. 1. The system is armed, a window is open, the door is closed and the panic button is not pressed. Does the siren sound?

    • aYes
    • bOnly if the door also opens
    • cIt depends on the time
    • dNo
    Show answer

    A: Yes

    X = 1, Y = 1, S = 1.

  2. 2. The system is not armed, the door is open and the panic button is not pressed. Does the siren sound?

    • aNo
    • bOnly if a window opens
    • cYes
    • dOnly if the system is armed later
    Show answer

    A: No

    Y = 0 and P = 0.

  3. 3. The system is not armed, all doors and windows are closed, and someone presses the panic button. What happens?

    • aThe siren sounds
    • bThe system arms itself
    • cOnly the window alarm sounds
    • dNothing happens
    Show answer

    A: The siren sounds

    S = Y OR P = 1.

  4. 4. How many rows does the complete truth table of the network have?

    • a8
    • b32
    • c16
    • d4
    Show answer

    C: 16

    Four inputs: 2⁴.

  5. 5. What does a NAND gate output when both inputs are 1?

    • aEither value
    • b0
    • cIt has no output
    • d1
    Show answer

    B: 0

    AND gives 1; NOT turns it into 0.

  6. 6. Which gate outputs 1 when exactly one of its two inputs is 1?

    • aAND
    • bXOR
    • cNOR
    • dNAND
    Show answer

    B: XOR

    Exclusive OR.

Testlet 2

A vending machine as a finite-state machine

Many technical systems behave differently depending on what has happened before. A traffic light, a lift or a vending machine must remember its current situation, its state, and respond to inputs by changing to another state and producing outputs. Such systems are modelled as finite-state machines: they have a finite number of states, one of which is the current state, and a set of transitions that specify, for each state and input, the next state and any output.

A state machine is described by a state diagram, in which states are circles and transitions are arrows labelled with the input that triggers them, or by a transition table. To trace the behaviour of a machine, one starts in the initial state and applies the inputs one after another, noting each new state and output. Inputs for which no transition is defined are usually ignored, so the machine stays in its current state.

State machines are used to design control software, communication protocols and user interfaces, because they make every possible situation explicit. Engineers check a design for unreachable states, which can never occur, and for situations without a defined response, which could cause the system to hang.

Timing diagrams show how signals change over time and are used to check that a machine responds correctly to sequences of inputs. Each signal is drawn as a line that is high or low, and changes of state happen at defined moments, for example at the rising edge of a clock signal.

Real vending machines have many more states, for example for selecting a product, for running out of change or for a jammed bottle, but the principle is the same.

A simple drinks machine sells a bottle for 1 euro and accepts only 50-cent and 1-euro coins. It has three states: S0 (no credit), S50 (50 cents credit) and a "dispense" action. If more than 1 euro is inserted, it returns the excess. The inputs are c50 (a 50-cent coin), c100 (a 1-euro coin) and R (the return button, which gives back any credit).

Transition table
Current stateInputNext stateOutput
S0c50S50none
S0c100S0dispense bottle
S50c50S0dispense bottle
S50c100S0dispense bottle, return 50 cents
S50RS0return 50 cents
S0RS0none
  1. 1. Starting in S0, a customer inserts c50 and then c50. What happens?

    • aA bottle is dispensed and the machine returns to S0
    • bNothing is dispensed yet
    • cOne euro is returned
    • dThe machine stays in S50 and waits for another coin
    Show answer

    A: A bottle is dispensed and the machine returns to S0

    S0 → S50 → S0 with dispense.

  2. 2. Starting in S0, the inputs are c50, R. What is the final state?

    • aS0, with 50 cents returned
    • bS0, with a bottle dispensed
    • cS50, with no output
    • dS50, with 50 cents returned
    Show answer

    A: S0, with 50 cents returned

    R in S50 returns the credit.

  3. 3. Starting in S0, the inputs are c50, c100. What is the output?

    • aA bottle and 50 cents change
    • bOnly 50 cents change and no bottle
    • cTwo bottles
    • dOnly a bottle
    Show answer

    A: A bottle and 50 cents change

    1.50 euros inserted for a 1-euro bottle.

  4. 4. Starting in S0, the inputs are c100, c50, c50, c100. How many bottles are dispensed?

    • a4
    • b1
    • c3
    • d2
    Show answer

    C: 3

    c100 → bottle; c50, c50 → bottle; c100 → bottle.

  5. 5. In which state is the machine after the input sequence c50, c50, c50?

    • aDispense
    • bS50
    • cIt is undefined
    • dS0
    Show answer

    B: S50

    S0 → S50 → S0 (bottle) → S50.

  6. 6. Why do engineers check a state machine for undefined transitions?

    • aThey make the machine sell more drinks per hour of operation
    • bThe system could hang in an unexpected situation
    • cThey are required for timing diagrams
    • dThey reduce the number of states
    Show answer

    B: The system could hang in an unexpected situation

    Every input in every state needs a defined response.

How to work a testlet

Other Engineering topics

Mathematics and statisticsPhysicsChemistryMaterialsTechnical mechanicsThermodynamicsElectrical engineeringDevelopment and construction

Full Engineering module guide

Start practicing free

One diagnostic, a projected score, and your first unit. No card, no time limit on the free tier.

Start free, no card needed