# -*- coding: utf-8 -*-
# Copyright (c) 2021, Silvio Peroni <essepuntato@gmail.com>
#
# Permission to use, copy, modify, and/or distribute this software for any purpose
# with or without fee is hereby granted, provided that the above copyright notice
# and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.


# Test case for the function
def test_smc(a, b, expected):
    result = smc(a, b)
    if round(expected, 3) == round(result, 3):
        return True
    else:
        return False


# Code of the function
def smc(a, b):
    result = {
        (True, True): 0,
        (True, False): 0,
        (False, True): 0,
        (False, False): 0
    }

    for k in a:
        result[a[k], b[k]] += 1

    num = result[(True, True)] + result[(False, False)]
    den = num + result[(False, True)] + result[(True, False)]

    return num / den


# Tests
print(test_smc({"a": True, "b": True}, {"a": False, "b": False}, 0/2))
print(test_smc({"a": True, "b": True}, {"a": True, "b": True}, 2/2))
print(test_smc({"a": True, "b": False}, {"a": True, "b": True}, 1/2))
print(test_smc({"a": True, "b": False}, {"a": False, "b": False}, 1/2))
print(test_smc({"a": True, "b": False, "c": False}, {"a": False, "b": False, "c": False}, 2/3))
