Skip to content

Commit

Permalink
Create test.yml (#1)
Browse files Browse the repository at this point in the history
added GitHub Workflow for tests and flake8 lints.
fixes to pass the workflow
  • Loading branch information
Vipul-Cariappa authored Oct 22, 2023
1 parent 878f07a commit 1b6503e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 13 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 mypy
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
flake8 ./tests/*.py ./logic/*.py --max-line-length=120
- name: Type checker with mypy
run: |
mypy ./tests/*.py ./logic/*.py
- name: Test with python unittest
run: |
python -m unittest tests/*.py --verbose
22 changes: 15 additions & 7 deletions logic/proof.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
from typing import Sequence, Generator, Iterator, TypeAlias
from .proposition import *
from typing import Sequence, Generator, Iterator, TypeAlias, Any
from .proposition import (
Statement,
CompositePropositionAND,
CompositePropositionNOT,
CompositePropositionOR,
CompositePropositionBICONDITIONAL,
CompositePropositionCONDITIONAL,
)

from enum import Enum

AssumptionT: TypeAlias = "Assumption"
ProofT: TypeAlias = "Proof"


class RulesOfInference(Enum):
Expand All @@ -21,7 +29,7 @@ class RulesOfInference(Enum):


class Assumption:
def __init__(self, assumptions: Sequence[Statement] | Self) -> None:
def __init__(self, assumptions: Sequence[Statement] | AssumptionT) -> None:
if isinstance(assumptions, Assumption):
self.assumptions: set[Statement] = set(assumptions.assumptions)
else:
Expand All @@ -31,10 +39,10 @@ def __contains__(self, key: Any) -> bool:
return key in self.assumptions

def with_proposition(self, prop: Statement) -> Generator[Statement, None, None]:
l = prop.extract()
individual_propositions = prop.extract()
for i in self.assumptions:
yielded = False
for j in l:
for j in individual_propositions:
if j in i and not yielded:
yielded = True
yield i
Expand All @@ -56,7 +64,7 @@ def __init__(self) -> None:
def add(self, roi: RulesOfInference, *statement: Statement) -> None:
self.proof.append((roi, (*statement,)))

def extend(self, proof: Self) -> None:
def extend(self, proof: ProofT) -> None:
self.proof.extend(proof.proof)

def __iter__(self) -> Iterator[tuple[RulesOfInference, tuple[Statement, ...]]]:
Expand Down Expand Up @@ -244,7 +252,7 @@ def prove(self) -> tuple[Proof, bool]:
self.proof.add(RulesOfInference.Resolution, i)
self.proof.extend(proof)
return self.proof, True

# Applying Disjunctive Syllogism
if self.conclusion == first:
proof, truth = Prover(self.assumptions.remove(i), ~second).prove()
Expand Down
12 changes: 6 additions & 6 deletions logic/proposition.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Self, Any, TypeAlias
from typing import Any, TypeAlias
from copy import copy
from abc import ABC, abstractmethod
from warnings import warn
Expand Down Expand Up @@ -27,27 +27,27 @@ def extract(self) -> list[PropositionT]:
def __contains__(self, key: Any) -> bool:
pass

def __and__(self, other: Any) -> CompositePropositionT:
def __and__(self, other: Any) -> StatementT:
if not isinstance(other, Statement):
raise TypeError(f"Cannot perform logical and of {type(self)} with {type(other)}")
return CompositePropositionAND(self, other)

def __or__(self, other: Any) -> CompositePropositionT:
def __or__(self, other: Any) -> StatementT:
if not isinstance(other, Statement):
raise TypeError(f"Cannot perform logical or of {type(self)} with {type(other)}")
return CompositePropositionOR(self, other)

def __invert__(self) -> CompositePropositionT:
def __invert__(self) -> StatementT:
if isinstance(self, CompositePropositionNOT):
return copy(self.statement)
return CompositePropositionNOT(self)

def __truediv__(self, other: Any) -> CompositePropositionT:
def __truediv__(self, other: Any) -> StatementT:
if not isinstance(other, Statement):
raise TypeError(f"Cannot perform logical imply of {type(self)} with {type(other)}")
return CompositePropositionCONDITIONAL(self, other)

def __mod__(self, other: Any) -> CompositePropositionT:
def __mod__(self, other: Any) -> StatementT:
if not isinstance(other, Statement):
raise TypeError(f"Cannot perform logical bi-conditional of {type(self)} with {type(other)}")
return CompositePropositionBICONDITIONAL(self, other)
Expand Down

0 comments on commit 1b6503e

Please sign in to comment.