The following is for a programming test I was once given for a job interview. I am not a good test-taker. My solution is below, and I am just looking for some insights as to why my solution was not accepted:
I need to write a program in VB.Net which copies from input to output until the input is exhausted. The program should use (and NOT implement) the methods
GetData()
and
PutData()
described below.
The method
GetData()
provides input. Its function prototype is:
Public Function GetData(ByRef Buf() As Char) As Integer
It returns the number of characters placed into
Buf
, a value less than or equal to 512. This number varies from one call to the next. If it is 0, input is exhausted.
The method
PutData()
accepts output. Its function prototype is:
Public Sub PutData(ByVal Buf() as Char, ByVal Count As Integer)
It writes
Count
characters to output from
Buf
. Count must represent the number of characters contained in
Buf
and be 512 for every call but the last. It may be less than 512 (even 0) for the last call only.
The above is a programming test I was once given as a interview.
I submitted the following code:
I wrote the code below for the answer to this test, and the hiring manager said I was wrong because I was making assumptions:
Sub Main()
Dim buffer As Char() = New Char(512) {}
Dim count As Integer = 0
While (InlineAssignHelper(count, GetData(buffer))) <> 0
PutData(buffer, count)
End While
End Sub
Private Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
target = value
Return value
End Function
The hiring manager said i was wrong for making assumptions. Can anyone please tell me why this code does not answer the programming test, or is this interviewer being a patronizing douche bag that doesn't know what the F$CK he is talking about?
What's tripping me up is that there seems to be a 'sequence' involved in what the hiring manager is saying. However, I don't get it...if I have a
GetData()
method that is essentially a black-box "reader", how can I know, a priori, the data block sequence?
Personally i think this programming test was written by a dummy, a one-size-fits-all hiring manager who doesn't know a thing about coding but just was handed some piece of paper by their boss and the boss is saying, "here give everyone that applies this impossible-to-pass test."
Brian