def test_accuracy_top3():
    """
    Tests for catalyst.metrics.accuracy metric.
    """
    outputs = (
        torch.linspace(0, NUM_CLASSES - 1, steps=NUM_CLASSES)
        .repeat(1, BATCH_SIZE)
        .view(-1, NUM_CLASSES)
    )

    for i in range(NUM_CLASSES):
        targets = torch.ones((BATCH_SIZE, 1)) * i

        top1, top3, top5 = accuracy(outputs, targets, topk=(1, 3, 5))
        assert np.isclose(top1, 1 if i >= NUM_CLASSES - 1 else 0)
        assert np.isclose(top3, 1 if i >= NUM_CLASSES - 3 else 0)
        assert np.isclose(top5, 1 if i >= NUM_CLASSES - 5 else 0)

    Tests for catalyst.metrics.accuracy metric.
    
tests/catalyst/metrics/functional/test_accuracy.py