from __future__ import annotations

import numpy as np
import torch.nn as nn

from early_warning_suite.config import SuiteConfig
from early_warning_suite.model import MultiTaskNet, effective_number_weights


def test_model_matches_baseline_architecture():
    model = MultiTaskNet(10, SuiteConfig())
    modules = list(model.trunk)
    assert isinstance(modules[0], nn.Linear)
    assert isinstance(modules[1], nn.BatchNorm1d)
    assert isinstance(modules[2], nn.ReLU)
    assert isinstance(modules[3], nn.Dropout)
    assert model.reg_head[0].out_features == 64
    assert model.cls_head[0].out_features == 64


def test_effective_number_weights_have_sample_mean_one_and_positive_is_larger():
    y = np.array([1, 0, 0, 0, 0], dtype=np.float32)
    w, low, high = effective_number_weights(y, beta=0.9999)
    assert np.isclose(w.mean(), 1.0)
    assert low > high
    assert np.isclose(w[0], low)
