readyforhires

Intermediate Go test (Intermediate)

30 questions · 35 minutes · Free

Interfaces, goroutines, channels and testing.

Take the Intermediate Go test

What it covers

Interview format

Earn a certificate

The Intermediate Go test is one of the 6 tests of the Go Backend Developer: Intermediate learning path. Pass it and the other 5 tests at 70% or more and readyforhires issues you a verifiable certificate in your name, with its own code and verify link to share or add to LinkedIn.

Sample learning path certificate for Go Backend Developer: Intermediate, made out to “Your name” and marked SAMPLE
Pass with 70% or more to earn a verifiable certificate. This is a sample: yours carries your name, the date you earned it and its own verify code.

Sample questions

5 sample questions from the Intermediate Go test, with the answers. Samples are taken out of the live test, so you will not meet these when you sit it.

  1. Which of the following statements accurately describes the behavior of the select statement in Go?

    1. The select statement blocks until at least one of the communication operations (send or receive) can proceed.
    2. The select statement is a loop construct for iterating over channels.
    3. The select statement is used for sequential execution of goroutines.
    4. The select statement always executes the first case in the order they are written.

    Answer: A. The select statement blocks until at least one of the communication operations (send or receive) can proceed.

    The select statement in Go is used to wait on multiple communication operations. It blocks until at least one of the cases can proceed. If multiple cases can proceed, the choice is made randomly. This is different from other options, which either describe incorrect behavior or are not specific to the select statement.

  2. What happens when a receiver attempts to read from an unbuffered channel that has not yet received a value?

    1. The receiver will receive the value without any blocking.
    2. The receiver will immediately receive the value if it is sent later.
    3. The receiver will block until the sender sends a value.
    4. The sender will not block and the receiver will not block.

    Answer: C. The receiver will block until the sender sends a value.

    In Go, when using an unbuffered channel, the sender will block until the receiver is ready to receive the value, and the receiver will block until the sender sends a value. This synchronization behavior is a key characteristic of unbuffered channels.

  3. Which statement accurately describes the behavior of a buffered channel with a capacity of 5 compared to an unbuffered channel?

    1. A buffered channel with a capacity of 5 can only hold 1 value, while an unbuffered channel can hold up to 5 values.
    2. A buffered channel with a capacity of 5 can be used without any receiver, while an unbuffered channel requires both a sender and a receiver to be present.
    3. A buffered channel with a capacity of 5 can be used for asynchronous communication, while an unbuffered channel is used for synchronous communication.
    4. A buffered channel with a capacity of 5 can hold up to 5 values without blocking the sender, while an unbuffered channel requires a receiver to be ready before a send operation can complete.

    Answer: D. A buffered channel with a capacity of 5 can hold up to 5 values without blocking the sender, while an unbuffered channel requires a receiver to be ready before a send operation can complete.

    A buffered channel with a specified capacity allows for non-blocking sends up to that capacity, whereas an unbuffered channel requires synchronization between the sender and receiver. This makes buffered channels suitable for scenarios where the sender and receiver may not be perfectly synchronized, while unbuffered channels are better for ensuring immediate communication.

  4. In a Go program, what is the behavior of the 'default' clause in a 'select' statement when no other cases are ready?

    1. The default case is optional and cannot be used with other cases.
    2. The default case is used to send data to all channels simultaneously.
    3. The default case will execute if no other case matches, ensuring the select statement does not block indefinitely.
    4. The default case is executed only when all other cases are blocked.

    Answer: C. The default case will execute if no other case matches, ensuring the select statement does not block indefinitely.

    In Go, the 'select' statement with a 'default' clause allows a goroutine to proceed without blocking if no other channel operations are ready. This is useful in scenarios where you want to avoid deadlock by providing a fallback action.

  5. Which approach is most appropriate for benchmarking CPU usage in Go, and when should each be used?

    1. Use `testing.B.N` to measure CPU time directly and `runtime.CPUProfile` for measuring wall-clock time.
    2. Use `testing.B.N` to measure CPU usage directly and `runtime.CPUProfile` for detailed profiling.
    3. Use `testing.B.N` for measuring wall-clock time and `runtime.CPUProfile` for measuring CPU time.
    4. Use `testing.B.N` for detailed CPU profiling and `runtime.CPUProfile` for general performance measurement.

    Answer: B. Use `testing.B.N` to measure CPU usage directly and `runtime.CPUProfile` for detailed profiling.

    When benchmarking CPU usage, `testing.B.N` provides a high-level measurement of how long the benchmark runs, which is useful for comparing performance between different implementations. However, for detailed CPU profiling, `runtime.CPUProfile` is used. This is because `testing.B.N` focuses on the overall time taken, while `runtime.CPUProfile` provides more granular insights into CPU usage, such as which functions are consuming the most CPU time.

Frequently asked questions

How many questions are in the Intermediate Go test?
30 questions (18 multiple choice, 9 multi-answer, 3 predict-the-output), with 35 minutes to answer them.
What does the Intermediate Go test cover?
Interfaces and embedding, Goroutines and channels, select and sync, context, Testing and benchmarks.
Is the Intermediate Go test free?
Yes. It is free to take with a readyforhires account.
What level is the Intermediate Go test?
Intermediate, in Backend.

More Backend tests

Roles that test these skills

Companies that test these skills

All practice tests · All Backend tests

Last updated