# Path: fedjax/datasets/emnist.py
# SPLITS = ('train', 'test')
# def cite():
# def load_split(split: str,
#                only_digits: bool = False,
#                mode: str = 'sqlite',
#                cache_dir: Optional[str] = None) -> federated_data.FederatedData:
# def domain_id(client_id: federated_data.ClientId) -> int:
# def preprocess_client(
#     client_id: federated_data.ClientId,
#     examples: client_datasets.Examples) -> client_datasets.Examples:
# def preprocess_batch(
#     examples: client_datasets.Examples) -> client_datasets.Examples:
# def preprocess_split(
#     fd: federated_data.FederatedData) -> federated_data.FederatedData:
# def load_data(
#     only_digits: bool = False,
#     mode: str = 'sqlite',
#     cache_dir: Optional[str] = None
# ) -> Tuple[federated_data.FederatedData, federated_data.FederatedData]:


from absl.testing import absltest
from fedjax.datasets import emnist
import numpy as np
import numpy.testing as npt
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for fedjax.datasets.emnist.

This file only tests preprocessing functions.
"""



class EmnistTest(absltest.TestCase):

  def test_domain_id(self):
    with self.subTest('invalid'):
      with self.assertRaisesRegex(ValueError, 'Invalid client_id'):
        emnist.domain_id(b'not_emnist')

    with self.subTest('domain 0'):
      for client_id in [b'f2100_xx', b'f2222_yy', b'f2599_zz']:
        self.assertEqual(emnist.domain_id(client_id), 0)
        self.assertEqual(emnist.domain_id(b'A' * 16 + b':' + client_id), 0)

    with self.subTest('domain 1'):
      for client_id in [b'f0000_xx', b'f2099_yy', b'f2600_zz', b'f9999_99']:
        self.assertEqual(emnist.domain_id(client_id), 1)

# Path: fedjax/datasets/emnist.py
# SPLITS = ('train', 'test')
# def cite():
# def load_split(split: str,
#                only_digits: bool = False,
#                mode: str = 'sqlite',
#                cache_dir: Optional[str] = None) -> federated_data.FederatedData:
# def domain_id(client_id: federated_data.ClientId) -> int:
# def preprocess_client(
#     client_id: federated_data.ClientId,
#     examples: client_datasets.Examples) -> client_datasets.Examples:
# def preprocess_batch(
#     examples: client_datasets.Examples) -> client_datasets.Examples:
# def preprocess_split(
#     fd: federated_data.FederatedData) -> federated_data.FederatedData:
# def load_data(
#     only_digits: bool = False,
#     mode: str = 'sqlite',
#     cache_dir: Optional[str] = None
# ) -> Tuple[federated_data.FederatedData, federated_data.FederatedData]:


# Path: fedjax/datasets/emnist_test.py
from absl.testing import absltest
from fedjax.datasets import emnist
import numpy as np
import numpy.testing as npt

#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for fedjax.datasets.emnist.

This file only tests preprocessing functions.
"""



class EmnistTest(absltest.TestCase):

  def test_domain_id(self):
    with self.subTest('invalid'):
      with self.assertRaisesRegex(ValueError, 'Invalid client_id'):
        emnist.domain_id(b'not_emnist')

    with self.subTest('domain 0'):
      for client_id in [b'f2100_xx', b'f2222_yy', b'f2599_zz']:
        self.assertEqual(emnist.domain_id(client_id), 0)
        self.assertEqual(emnist.domain_id(b'A' * 16 + b':' + client_id), 0)

    with self.subTest('domain 1'):
      for client_id in [b'f0000_xx', b'f2099_yy', b'f2600_zz', b'f9999_99']:
        self.assertEqual(emnist.domain_id(client_id), 1)

        self.assertEqual(emnist.domain_id(b'A' * 16 + b':' + client_id), 1)