<commit_before>#!/usr/bin/env python
# File created on 15 Jul 2011
from __future__ import division

__author__ = "<NAME>"
__copyright__ = "Copyright 2014, The MetadataMenagerie Project"
__credits__ = ["<NAME>"]
__license__ = "GPL"
__version__ = "0.1dev"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL>"
__status__ = "Development"

"""Tests the parallel_sets library functions."""

from cogent.util.unit_test import TestCase, main
from md_menagerie.mapping import MappingTable
from md_menagerie.parallel_sets import get_top_level_sets_from_mapping,\
  intersect_two_set_dicts


class ParallelSetsTests(TestCase):
    """Tests of the plots module."""
    def setUp(self):
        """Create some data to be used in the tests."""
        self.ParallelSetsTableLines =\
        ["#SampleID\tTemp\tTissueLoss\tAlgalContact\tDescription\n",\
         "#Comment line, full of crazy comments\n",\
         "#Another comment line\n",\
         "S.1\t21.0\tLoss\tYes\tSample.1.Description\n",\
         "S.2\t22.0\tLoss\tYes\tSample.2.Description\n",\
         "S.3\t23.0\tLoss\tNo\tSample.3.Description\n",\
         "S.4\t20.0\tNo_Loss\tNo\tSample.4.Description\n",\
         "S.5\t21.0\tLoss\tYes\tSample.5.Description\n",\
         "S.5b\t21.0\tNo_Loss\tNo\tSample.5.Description\n",\
         "S.6\t21.5\tNo_Loss\tNo\tSample.6.Description\n",\
         "S.7\t22.72\tLoss\tNo\tSample.7.Description\n",\
         "S.8\t23.14\tLoss\tYes\tSample.7.Description\n"]

        self.ParallelSetsTable =\
          MappingTable(self.ParallelSetsTableLines)

    def test_get_top_level_sets_from_mapping_OK_valid_input(self):
        """get_top_level_sets_from_mapping OK with valid input"""
        #parallel_sets form mapping should contruct
        #a dict of sets of samples, corresponding to different
        #subdivisions of the data.<commit_msg>Fixed failing test in parallel_sets_from_dict_of_set_dicts<commit_after>#!/usr/bin/env python
# File created on 15 Jul 2011
from __future__ import division

__author__ = "<NAME>"
__copyright__ = "Copyright 2014, The MetadataMenagerie Project"
__credits__ = ["<NAME>"]
__license__ = "GPL"
__version__ = "0.1dev"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL>"
__status__ = "Development"

"""Tests the parallel_sets library functions."""

from cogent.util.unit_test import TestCase, main
from md_menagerie.mapping import MappingTable
from md_menagerie.parallel_sets import get_top_level_sets_from_mapping,\
  intersect_two_set_dicts, parallel_sets_from_dict_of_set_dicts


class ParallelSetsTests(TestCase):
    """Tests of the plots module."""
    def setUp(self):
        """Create some data to be used in the tests."""
        self.ParallelSetsTableLines =\
        ["#SampleID\tTemp\tTissueLoss\tAlgalContact\tDescription\n",\
         "#Comment line, full of crazy comments\n",\
         "#Another comment line\n",\
         "S.1\t21.0\tLoss\tYes\tSample.1.Description\n",\
         "S.2\t22.0\tLoss\tYes\tSample.2.Description\n",\
         "S.3\t23.0\tLoss\tNo\tSample.3.Description\n",\
         "S.4\t20.0\tNo_Loss\tNo\tSample.4.Description\n",\
         "S.5\t21.0\tLoss\tYes\tSample.5.Description\n",\
         "S.5b\t21.0\tNo_Loss\tNo\tSample.5.Description\n",\
         "S.6\t21.5\tNo_Loss\tNo\tSample.6.Description\n",\
         "S.7\t22.72\tLoss\tNo\tSample.7.Description\n",\
         "S.8\t23.14\tLoss\tYes\tSample.7.Description\n"]

        self.ParallelSetsTable =\
          MappingTable(self.ParallelSetsTableLines)
   
        self.DictOfSetDicts =\
          {"Temp":{"high":set(['S.8','S.7','S.2','S.3']),
                   "low":set(['S.1','S.4','S.5','S.5b','S.6'])},
           "Algae":{"algae":set(['S.1','S.2','S.5','S.8']),
                    "no_algae":set(['S.3','S.4','S.5b','S.6','S.7'])}
          }

        
    
    def test_parallel_sets_from_dict_of_set_dicts_OK_valid_input(self):
        """parallel_sets_from_set_dict function with valid input data"""
        temp_algae = self.DictOfSetDicts
        categories = ["Algae","Temp"]
        exp_top_level = temp_algae["Algae"]
        exp_bottom_level =\
        {
          ("algae","high"):set(["S.8","S.2"]),
          ("algae","low"):set(["S.1","S.5"]),
          ("no_algae","high"):set(["S.3","S.7"]),
          ("no_algae","low"):set(["S.4","S.6","S.5b"])
        }
        exp = [exp_top_level,exp_bottom_level]
        obs = parallel_sets_from_dict_of_set_dicts(temp_algae,categories)
        self.assertEqualItems(obs,exp)

    def test_get_top_level_sets_from_mapping_OK_valid_input(self):
        """get_top_level_sets_from_mapping OK with valid input"""
        #parallel_sets form mapping should contruct
        #a dict of sets of samples, corresponding to different
        #subdivisions of the data.
{'fraction_non_alphanumeric': 0.15232067510548522, 'fraction_numerical': 0.03059071729957806, 'mean_word_length': 3.045221843003413, 'pattern_counts': {'":': 6, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1655321', 'n_tokens_mistral': 1797, 'n_tokens_neox': 1709, 'n_words': 265}