text: # DISTRIBUTION STATEMENT A. Approved for public release: distribution unlimited.
  #
  # This material is based upon work supported by the Assistant Secretary of Defense for Research and
  # Engineering under Air Force Contract No. FA8721-05-C-0002 and/or FA8702-15-D-0001. Any opinions,
  # findings, conclusions or recommendations expressed in this material are those of the author(s) and
  # do not necessarily reflect the views of the Assistant Secretary of Defense for Research and
  # Engineering.
  #
  # © 2018 Massachusetts Institute of Technology.
  #
  # MIT Proprietary, Subject to FAR52.227-11 Patent Rights - Ownership by the contractor (May 2014)
  #
  # The software/firmware is provided to you on an As-Is basis
  #
  # Delivered to the U.S. Government with Unlimited Rights, as defined in DFARS Part 252.227-7013 or
  # 7014 (Feb 2014). Notwithstanding any copyright notice, U.S. Government rights in this work are
  # defined by DFARS 252.227-7013 or DFARS 252.227-7014 as detailed above. Use of this work other than
  # as specifically authorized by the U.S. Government may violate any copyrights that exist in this
  # work.
  
  from datasets.cifar20 import CIFAR20
  from datasets.cifar80 import CIFAR80
  from datasets.cifar100 import CIFAR100
  from datasets.cifar10 import CIFAR10
  from datasets.gaussian_noise import GaussianNoise
  from datasets.uniform_noise import UniformNoise
  from datasets.isun import ISUN
  from datasets.lsun_crop import LSUNCrop
  from datasets.lsun_resize import LSUNResize
  from datasets.tinyimagenet_crop import TinyImageNetCrop
  from datasets.tinyimagenet_resize import TinyImageNetResize
  
  from OutOfDomain import DATASETS_DIR
  from OutOfDomain.data_loaders.domain_data_loader import build_domain_data_loader
  
  import matplotlib.pyplot as plt
  import numpy as np
  
  """
  Test Cases for making sure our datasets are working well
  Take a look at the README. It will tell you where you can 
  download the data and how what your directory structure should
  look like. 
  """
  
  datasets = ['cifar10', 'cifar20', 'cifar80', 'cifar100', 'gaussian_noise',
              'uniform_noise', 'isun', 'lsun_crop', 'lsun_resize',
              'tinyimagenet_crop', 'tinyimagenet_resize']
  
  domain_datasets = ['gaussian_noise', 'uniform_noise', 'isun', 'lsun_crop', 'lsun_resize',
                     'tinyimagenet_crop', 'tinyimagenet_resize']
  
  
  def create_describe_and_show_dataset(dataset_name):
      dataset = __build_dataset(dataset_name)
      print("----------------- " + dataset_name + " ---------------")
      print("length : " + str(len(dataset)))
      if hasattr(dataset, 'targets'):
          print("data type : " + str(type(dataset[2][0])))
          print("shape : " + str(np.array(dataset[2][0]).shape))
          print("Max label : " + str(max(dataset.targets)))
          plt.imshow(dataset[2][0])
          plt.show()
      else:
          print("data type : " + str(type(dataset[2])))
          print("shape : " + str(np.array(dataset[2]).shape))
          print("This dataset has no targets")
          plt.imshow(dataset[2])
          plt.show()
  
  
  def __build_dataset(dataset_name):
      assert (dataset_name in datasets), "Error: The supported datasets include " + str(datasets)
      if dataset_name == 'cifar10':
          return CIFAR10(DATASETS_DIR)
      elif dataset_name == 'cifar20':
          return CIFAR20(DATASETS_DIR)
      elif dataset_name == 'cifar80':
          return CIFAR80(DATASETS_DIR)
      elif dataset_name == 'cifar100':
          return CIFAR100(DATASETS_DIR)
      elif dataset_name == 'gaussian_noise':
          return GaussianNoise()
      elif dataset_name == 'uniform_noise':
          return UniformNoise()
      elif dataset_name == 'isun':
          return ISUN(DATASETS_DIR)
      elif dataset_name == 'lsun_crop':
          return LSUNCrop(DATASETS_DIR)
      elif dataset_name == 'lsun_resize':
          return LSUNResize(DATASETS_DIR)
      elif dataset_name == 'tinyimagenet_crop':
          return TinyImageNetCrop(DATASETS_DIR)
      elif dataset_name == 'tinyimagenet_resize':
          return TinyImageNetResize(DATASETS_DIR)
      return
  
  
  def test_domain_data_loader(dataset_name):
      """
      Test that the data loaders work for domains
      :param dataset_name: which domain did the images come from
      :return:
      """
      assert (dataset_name in domain_datasets), "Error: The supported datasets include " + str(domain_datasets)
  
      val_loader, test_loader = build_domain_data_loader('gaussian_noise')
      print("----------------- " + dataset_name + " ---------------")
      print("Length val: " + str(len(val_loader)))
      print("Length test: " + str(len(test_loader)))
      for imgs in val_loader:
          print("shape of a batch : " + str(imgs.shape))
          break
  
  
  if __name__ == '__main__':
      # for dataset in datasets:
      #     create_describe_and_show_dataset(dataset)
      for domain_dataset in domain_datasets:
          test_domain_data_loader(domain_dataset)
  