import numpy as np

def test(dnn, testing_data, show=False):

    # Track the classification results and performance for each data point.
    outputs = []    
    scorecard = []    
    
    # Query the network.
    for data in testing_data:
        
        # Convert the testing data into an array, removing commas.
        data_array = data.split(',')
        
        # Get the correct label.
        correct_label = int(data_array[0])
        
        # Scale and shift the input so that it lies within [0.01, 0.99].
        input_layer = np.asfarray(data_array[1:])
            
        # Begin querying.
        output_layer = dnn.query(input_layer) 
        
        # Get the predicted label.
        label = np.argmax(output_layer) 
        if show == True:
            print("Predicted label: " + str(label) + "\tCorrect label: " + \
                  str(correct_label))
        
        # Append the classification results.
        outputs.append(output_layer)        
        
        # Append a 1 if the prediction was correct and 0 otherwise.
        if(label == correct_label):
            scorecard.append(1)
        else:
            scorecard.append(0)

    # Return the classification results and performance.        
    return (outputs, scorecard)
    