-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de73728
commit 7b673cd
Showing
3 changed files
with
171 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
""" | ||
Unit tests for paradigm_utils.py | ||
""" | ||
|
||
import pytest | ||
import torch | ||
|
||
from osculari.paradigms import paradigm_utils | ||
|
||
|
||
def test_accuracy_binary_classification(): | ||
# Test accuracy for binary classification predictions | ||
output = torch.tensor([0.2, -0.1, 0.8, -0.4]).view(4, 1) | ||
target = torch.tensor([1, 0, 1, 0]) | ||
acc = paradigm_utils.accuracy(output, target) | ||
assert acc == 1.0 | ||
|
||
|
||
def test_accuracy_multi_classification(): | ||
# Test accuracy for multi-class predictions | ||
output = torch.tensor([[0.2, -0.1, 0.8, -0.4], [0.1, 0.3, -0.2, 0.5]]) | ||
target = torch.tensor([2, 0]) | ||
acc = paradigm_utils.accuracy(output, target) | ||
assert acc == 0.5 | ||
|
||
|
||
def test_accuracy_invalid_input(): | ||
# Test with invalid input (different shapes) | ||
output = torch.tensor([[0.2, -0.1, 0.8, -0.4], [0.1, 0.3, -0.2, 0.5]]) | ||
target = torch.tensor([2, 0, 1]) # Invalid target shape | ||
with pytest.raises(AssertionError): | ||
paradigm_utils.accuracy(output, target) | ||
|
||
|
||
def test_accuracy_zero_dimensional(): | ||
# Test with zero-dimensional input (should raise an error) | ||
output = torch.tensor(0.5) | ||
target = torch.tensor(1) | ||
with pytest.raises(AssertionError): | ||
paradigm_utils.accuracy(output, target) | ||
|
||
|
||
def test_accuracy_one_dimensional_equal(): | ||
# Test accuracy for one-dimensional predictions where output and target are equal | ||
output = torch.tensor([0.2, -0.1, 0.8, -0.4]).view(4, 1) | ||
target = torch.tensor([0, 0, 1, 0]) | ||
acc = paradigm_utils.accuracy(output, target) | ||
assert acc == 0.75 |