Skip to content

Commit

Permalink
react: Update tests to v2.0.0 (#1346)
Browse files Browse the repository at this point in the history
* react: re-implement according to canonical data

* react: update tests to v1.2.0

* react: correct test method name

* react: fix example solution py2-compatibility

* `copy()` method to `[:]`
* `clear()` method to reassigning an empty list

* react: refactor callbacks into pure functions

* Merge upstream/master into react-1257

pig-latin: improve documentation (#1352)

add "Running the tests" section to README template (#1271)

* add "Running the tests" section to README template

* regenerate README files with new template

* rewrite Running the tests section for clarity

* -switch to a plaintext-readable format
-add link explaining py.test vs pytest

queen-attack: re-implement according to canonical data 2.1.0 (#1351)

* queen-attack: re-implement according to canonical data 2.1.0

* queen-attack: rewrite to pass tests v2.1.0

* queen-attack: remove redundant tests

Rm `test_invalid_position_can_attack` since `Queen()`

grains: update tests to v1.1.0 (#1357)

Fix typo and minor style issues in all READMEs (#1356)

* Fix typo and style in README template

* Fix `shold` to `should`
* Fix minor style issues in `### Common pytest options`
* Add blank line after all headers

* Regenerate all READMEs

* Remove redundant periods in READMEs

add `awaiting review` exempt label to stale.yml (#1364)

go-counting: adapt tests to canonical data v1.0.0 (#1360)

* set correct canonical data version

* adapt tests and example solution to canonical data 1.0.0

* use assertSetEqual() consistently

sgf-parsing: implement exercise (#1359)

* implement sgf-parsing

* fix import statement

* create entry in config.json

* fix __eq__ for Python2

lens-person: forego exercise (#1299)

* lens-person: forego exercise

`lens-person` is specific to languages with immutable data (i.e. Haskell). This concept does not exist in Python, so the exercise should be foregone.

* remove bad comma

Implement exercise bank-account (#1260)

* Implement exercise bank-account

* bank-account: generate README using configlet

* bank-account: fix typo and comments

pascals-triangle: update tests to canonical-date v1.2.0 (#1164)

house: return singleton list for single verse (#1354)

* house: return singleton list for single verse

RE #1347 ([comment](#1347 (comment)))

* house: fix example solution to pass changed tests

meetup: remove fail-safe for undefined MeetupDayException (#1345)

* meetup: remove fail-safe for undefined MeetupDayException

Fixes #1344

* meetup: define MeetupDayException in example solution

* meetup: fix example solution to raise correct exception

* meetup: fix flake8 violations

* meetup: add exception message

Curriculum (#1355)

* select core exercises and set exercise ordering

* add missing obvious topics

* make list-ops a core exercise

* rational-numbers: increase difficulty

* unlocked_by core exercises only (exercism/configlet#61)
Ref: exercism/DEPRECATED.v2-feedback#61 (comment)

alphametics: mark computationally intensive test as extra-credit (#1358)

* alphametics: mark computationally intensive test as extra-credit

While this test is canonical, it does not technically add additional coverage. This test serves as a test for efficiency (exercism/problem-specifications#1024 (comment)) of a solution, not completeness.

Furthermore, here are the run-times for this exercise from the [latest Travis build]() (at the time of this writing):
| Python Version | Run-time (seconds) |
| --- | --- |
| 2.7 | 3.155 |
| 3.3 | 2.461 |
| 3.4 | 3.567 |
| 3.5 | 7.270 |
| 3.6 | 0.774 |

Notice that the optimized example solution is only "fast" in 3.6.

* alphametics: add to list of exercises allowed to skip tests in CI

bank-account: update README using configlet (#1366)

go-counting: update README to latest description (#1367)

bracket-push: update tests to v1.3.0 (#1369)

isbn-verifier: update tests to v2.4.0 (#1373)

* Replace test case - "invalid character in isbn"
* Add test case with only 9 digits

Python "bowling" test issue. (#1372)

Fixes /exercism/python/#1371.

yacht: implement exercise (#1368)

* yacht: implement exercise

* yacht: use enumeration of score categories

* Use enumeration instead of plain strings to represent categories
* Improve func `ns` in example solution

crypto-square: Clarify rectangular output requirement in README (#1375)

scale-generator: clarify docs. (#1374)

* Removed most mentions of terms that were irrelevant ("diminished interval") or undefined ("accidentals").
* Removed irrelevant table
* Some light reformatting

* react: update tests to v2.0.0
  • Loading branch information
mrcfps authored and cmccandless committed Apr 20, 2018
1 parent 4522136 commit 4478caf
Show file tree
Hide file tree
Showing 3 changed files with 261 additions and 204 deletions.
117 changes: 54 additions & 63 deletions exercises/react/example.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,56 @@
class Cell(object):
def __init__(self, reactor, value=0, dependencies=set(),
updater=None):
self.reactor = reactor
self.index = len(reactor.cells)
reactor.cells.append(self)
self.value = value
self.dirty = False
self.dependencies = dependencies
self.dependents = set()
self.updater = updater
self.watchers = set()
if updater is not None:
self.update()
self.notify()

def add_watcher(self, watcher):
self.watchers.add(watcher)

def remove_watcher(self, watcher):
self.watchers.remove(watcher)

def set_value(self, value, top=True):
self.value = value
for d in self.dependents:
d.update()
if top:
self.reactor.notify()

def update(self):
if self.updater is not None:
values = [d.value for d in self.dependencies]
value = self.updater(values)
if self.value != value:
self.set_value(value, False)
self.dirty = True

def notify(self):
if self.dirty:
for watcher in self.watchers:
watcher(self, self.value)
self.dirty = False

def __hash__(self):
return self.index


class Reactor(object):
def __init__(self):
self.cells = []

def create_input_cell(self, value):
return Cell(self, value=value)

def create_compute_cell(self, dependencies, updater):
cell = Cell(self,
dependencies=dependencies,
updater=updater)
for d in dependencies:
d.dependents.add(cell)
return cell

def notify(self):
for cell in self.cells:
cell.notify()
self._watchers = []
self._value = None
self.counter = 0

def add_watcher(self, cell):
self._watchers.append(cell)

@property
def value(self):
return self._value

@value.setter
def value(self, new_value):
self._value = new_value
self.counter += 1
for cell in self._watchers:
cell.compute()


class InputCell(Cell):
def __init__(self, initial_value):
super(InputCell, self).__init__()
self._value = initial_value


class ComputeCell(Cell):
def __init__(self, inputs, compute_function):
super(ComputeCell, self).__init__()
self.inputs = inputs
self.func = compute_function
self.callbacks = set()
self.compute()
self._register_inputs()

def _register_inputs(self):
for inp in self.inputs:
inp.add_watcher(self)

def compute(self):
# Only compute this cell when all inputs have same counters
if len(set([inp.counter for inp in self.inputs])) > 1:
return
new_val = self.func([inp.value for inp in self.inputs])
if new_val != self._value:
self.value = new_val
for cb in self.callbacks:
cb(new_val)

def add_callback(self, callback):
self.callbacks.add(callback)

def remove_callback(self, callback):
if callback in self.callbacks:
self.callbacks.remove(callback)
20 changes: 10 additions & 10 deletions exercises/react/react.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
class Cell(object):
def set_value(value):
pass
class InputCell(object):
def __init__(self, initial_value):
self.value = None

def add_watcher(self, watcher_callback):
pass

def remove_watcher(self, watcher_callback):
pass
class ComputeCell(object):
def __init__(self, inputs, compute_function):
self.value = None

def add_callback(self, callback):
pass

class Reactor(object):
def create_input_cell(self, value):
def remove_callback(self, callback):
pass

def create_compute_cell(self, dependencies, updater_callback):
def expect_callback_values(self, callback):

This comment has been minimized.

Copy link
@petertseng

petertseng Nov 24, 2018

Member
pass
Loading

0 comments on commit 4478caf

Please sign in to comment.