Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlota de la Vega committed May 14, 2024
1 parent 03d52db commit 03bf79e
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 1 deletion.
23 changes: 23 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Pytest

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
- name: Testing the code with pytest
run: |
pytest -v
Empty file added src/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion utils.py → src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import tensorflow as tf

from cGAN import conditionalGAN
from src.cGAN import conditionalGAN

batch_size = 64
num_channels = 1
Expand Down
38 changes: 38 additions & 0 deletions test/test_cgan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import tensorflow as tf
from src.cGAN import conditionalGAN

class TestConditionalGAN:
@classmethod
def setup_class(cls):
discriminator = tf.keras.models.Sequential()
generator = tf.keras.models.Sequential()
latent_dim = 100
image_size = 28
num_classes = 10
cls.cgan = conditionalGAN(discriminator, generator, latent_dim, image_size, num_classes)
cls.cgan.compile(
d_optimizer=tf.keras.optimizers.Adam(),
g_optimizer=tf.keras.optimizers.Adam(),
loss_fn=tf.keras.losses.BinaryCrossentropy(),
)

def test_train_step(self):
# Create dummy data for testing
real_images = tf.random.normal((32, 28, 28, 1))
one_hot_labels = tf.one_hot([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], depth=10)

# Perform a single train step
train_logs = self.cgan.train_step((real_images, one_hot_labels))

# Check if the loss values are updated
assert "g_loss" in train_logs
assert "d_loss" in train_logs
assert train_logs["g_loss"] != 0.0
assert train_logs["d_loss"] != 0.0

def test_metrics(self):
# Check if the metrics are correctly initialized
metrics = self.cgan.metrics
assert len(metrics) == 2
assert isinstance(metrics[0], tf.keras.metrics.Mean)
assert isinstance(metrics[1], tf.keras.metrics.Mean)
Empty file added test/test_gan.py
Empty file.

0 comments on commit 03bf79e

Please sign in to comment.