Closed alexxroche closed 3 years ago
How about this one instead?
diff --git a/src/content/en/posts/learning-to-fly-pt3.adoc b/src/content/en/posts/learning-to-fly-pt3.adoc
index caca364..e809fc7 100644
--- a/src/content/en/posts/learning-to-fly-pt3.adoc
+++ b/src/content/en/posts/learning-to-fly-pt3.adoc
@@ -2227,6 +2227,15 @@ pub trait Individual {
/* ... */
}
+
+/* ... */
+
+#[cfg(test)]
+impl Individual for TestIndividual {
+ fn create(chromosome: Chromosome) -> Self {
+ todo!()
+ }
+}
----
[NOTE]
All tests up to that point don't use Individual::create()
(so todo!()
won't hurt) + we're implementing proper ::create()
in the very next section (so there's no need to use chromosome.genes[0]
, which will get replaced in a moment anyway)
That might work. It wasn't clear that pub enum TestIndividual
was replacing pub struct TestIndividual
or why it wasn't an enum in the first place? Discovering a need to change to a difference data object in the middle of development is common, but there is always a reason.
It felt like you went from {A..F} and I'm wondering where B,C,D,E are? (Which might say more about my inability to keep up with your brilliant mind.)
It felt like you went from {A..F} and I'm wondering where B,C,D,E are?
Fair point - what do you think of this one?
commit 40e4584cfdd449efea8f18590e73f1ff4d83c961
Author: Patryk Wychowaniec <wychowaniec.patryk@gmail.com>
Date: Thu Apr 8 16:44:38 2021 +0200
posts(learning-to-fly-pt3): Highlight changing TestIndividual to enum
diff --git a/src/content/en/posts/learning-to-fly-pt3.adoc b/src/content/en/posts/learning-to-fly-pt3.adoc
index caca364..909ec74 100644
--- a/src/content/en/posts/learning-to-fly-pt3.adoc
+++ b/src/content/en/posts/learning-to-fly-pt3.adoc
@@ -2227,6 +2227,15 @@ pub trait Individual {
/* ... */
}
+
+/* ... */
+
+#[cfg(test)]
+impl Individual for TestIndividual {
+ fn create(chromosome: Chromosome) -> Self {
+ todo!()
+ }
+}
----
[NOTE]
@@ -2353,14 +2362,17 @@ We'll start by adjusting our `TestIndividual` so that instead of `panic!()`-ing,
Some tests - e.g. the ones for `RouletteWheelSelection` - don't care about genes at all, so we'll get bonus points for inventing a solution that doesn't require modifying those already-working tests.
-My proposition is:
+My proposition is to change `TestIndividual` from `struct` to an `enum` with two different variants:
[source, rust]
----
#[cfg(test)]
#[derive(Clone, Debug, PartialEq)]
pub enum TestIndividual {
+ /// For tests that require access to chromosome
WithChromosome { chromosome: Chromosome },
+
+ /// For tests that don't require access to chromosome
WithFitness { fitness: f32 },
}
(You can see it deployed at https://pwy.io/en/posts/learning-to-fly-pt3/.)
Which might say more about my inability to keep up with your brilliant mind.
No such thing! All unclear explanations are on me - no need to self-deprecate 🙂
Looks, to me, like you have created a perfect patch.
L710
pub struct TestIndividual
and then TestIndividual evolves into L2381pub enum TestIndividual
without ensuring that the previous section still passesfor i in fmt check test;do cargo $i; done