I want to be able to visit all the nodes of a tree in Rust. Last time, I showed the implementation of the tree itself, and code that would generate a random tree. This time, I’m going to show and describe code for walking around a tree and counting which nodes have a flag set. The code we’ll talk about this episode is here: Continue reading “Counting Fruit in Rust, Part 2”
Last time, I mentioned that I was starting up Rust again, and mentioned some helpful videos and thoughts that will help me as I take another swing at learning this language. The complete source for the examples I’ll use today is on GitHub, and you should be able to download it and
cargo run without much trouble. If you don’t have Rust and Cargo, you want to install rustup first.
Today, we’re going to generate a random tree, then we’re going to walk the tree recursively and count which nodes have a flag set. Here’s the code for representing the nodes and generating the tree: Continue reading “Counting Fruit in Rust”
Last time I messed with Rust, I made the classic beginner mistake of trying to learn too many things at once. I was trying to learn Rust, learn Lisp, and write a Lisp interpreter in Rust at the same time.
I started messing with Rust again. First, I want to mention a couple of videos that have really helped me understand Rust a little bit better.
Last time, I tried to find an easy way of running mutation testing on a rails app that’s tested by
minitest. I did not find an easy way, so today I’m going to try to do it the hard way: use an old PR on
mutant as a jumping off point to try to make a version of
mutant that hooks into
minitest. Continue reading “Mutant and Minitest”
I have a project at work that uses Minitest, but I want to use
mutant to test it. Mutant is a gem that does mutation testing. Mutation testing is an important complement to regular automated testing. Regular automated testing asserts that correct code passes your test suite; mutation testing asserts that incorrect code fails your test suite. In this series, I’m going to try to find the best way to mutation test a Rails app that’s covered mostly be minitest.
Last time, I made a simple model called
Lightswitch so that I could play with mutable state:
class Lightswitch < ActiveRecord::Base attr_accessor :turned_on def turn_on self.turned_on = true end end
When I first wrote the model, not wanting to suggest that my electrical fixtures were aroused, I named the attribute
on instead of
turned_on. I immediately saw some strange errors.
rake test started complaining that there was no column named
true. Today, I’m going to reproduce this error on purpose so that I will understand why, specifically, I can’t use
on as a column name with active record. Continue reading “Don’t YAML on, man (in Rails 4)”
Last time, I learned that using
let blocks in minitest cause minitest to define a method on the test class, and I hypothesized that this was to allow tests to share code while preventing them from sharing state. But the method that gets defined caches the results, so that the initializing block is only evaluated on the first call. I want to convince myself that test methods cannot corrupt this cache, or rather, can’t corrupt this cache without doing so on purpose. Continue reading “State and Caching in Minitest”
I want to know the difference between a few constructs in Ruby, specifically in minitest-spec-rails, so today I’m going to write several similar tests exploring different pieces of the DSL that minitest-spec-rails exposes, and look at the differing behaviors that result. Continue reading “Let blocks in Minitest”
I’ve been thinking about code reviews a lot lately.
My mom has often worked as an editor, and she once told me of the most difficult thing about being an editor (I paraphrase):
You have to let the writer keep his or her style. The challenge is to improve the writing without making it seem like you wrote it.
Working as a technical writer and as an English teacher, I thought about these things a lot. I would often think, “that is not a sentence that I would have written, but it is clear. It works.” Sometimes I would read a sentence and think, “I don’t know what that meant; that sentence doesn’t work.” I would change the sentence in the second situation but not the first. Continue reading “Throwing Darts at Code”
I’ve been thinking a lot about how and when I work recently. I missed a couple Wednesdays posting here, so I’ve been looking at ways to become more consistent.