|
@@ 455-474 (lines=20) @@
|
| 452 |
|
"The value must be correct" |
| 453 |
|
) |
| 454 |
|
|
| 455 |
|
def test___setitem__(self): |
| 456 |
|
context = MemoryContext({'mybool': bool, 'myint': int}, ['0', '1']) |
| 457 |
|
context.model['mybool']['0'] = True |
| 458 |
|
context.model['myint']['0'] = 1 |
| 459 |
|
self.assertEqual( |
| 460 |
|
str(context.population['0']), |
| 461 |
|
"{'mybool': True, 'myint': 1}", |
| 462 |
|
"The textual representation of the first individual is not correct" |
| 463 |
|
) |
| 464 |
|
context.model['mybool']['1'] = True |
| 465 |
|
context.model['myint']['1'] = 2 |
| 466 |
|
self.assertEqual( |
| 467 |
|
str(context.population['1']), |
| 468 |
|
"{'mybool': True, 'myint': 2}", |
| 469 |
|
"The textual representation of the first individual is not correct" |
| 470 |
|
) |
| 471 |
|
with self.assertRaises(KeyError): |
| 472 |
|
context.model['mybool']['unknown'] = 1 |
| 473 |
|
with self.assertRaises(ValueError): |
| 474 |
|
context.model['myint']['0'] = 'abc' |
| 475 |
|
|
| 476 |
|
def test___len__(self): |
| 477 |
|
context = MemoryContext({'mybool': bool, 'myint': int}, ['0', '1']) |
|
@@ 340-359 (lines=20) @@
|
| 337 |
|
with self.assertRaises(ValueError): |
| 338 |
|
_ = context.population['0'].value(other.model['myint']) |
| 339 |
|
|
| 340 |
|
def test___setitem__(self): |
| 341 |
|
context = MemoryContext({'mybool': bool, 'myint': int}, ['0', '1']) |
| 342 |
|
context.population['0']['mybool'] = True |
| 343 |
|
context.population['0']['myint'] = 1 |
| 344 |
|
self.assertEqual( |
| 345 |
|
str(context.population['0']), |
| 346 |
|
"{'mybool': True, 'myint': 1}", |
| 347 |
|
"The textual representation of the first individual is not correct" |
| 348 |
|
) |
| 349 |
|
context.population['1']['mybool'] = True |
| 350 |
|
context.population['1']['myint'] = 2 |
| 351 |
|
self.assertEqual( |
| 352 |
|
str(context.population['1']), |
| 353 |
|
"{'mybool': True, 'myint': 2}", |
| 354 |
|
"The textual representation of the first individual is not correct" |
| 355 |
|
) |
| 356 |
|
with self.assertRaises(KeyError): |
| 357 |
|
context.population['0']['unknown'] = 1 |
| 358 |
|
with self.assertRaises(ValueError): |
| 359 |
|
context.population['0']['myint'] = 'abc' |
| 360 |
|
|
| 361 |
|
def test___getitem__(self): |
| 362 |
|
context = MemoryContext({'mybool': bool, 'myint': int}, ['0']) |