Search code examples
dartchecksum

Is there anything like "CheckSum" in Dart (on Objects)?


For Testing purposes I'm trying to design a way to verify that the results of statistical tests are identical across versions, platforms and such. There are a lot things that go on that include ints, nums, dates, Strings and more inside our collections of Objects.

In the end I want to 'know' that the whole set of instantiated objects sum to the same value (by just doing something like adding the checkSum of all internal properties).

I can write low level code for each internal value to return a checkSum but I was thinking that perhaps something like this already exists.

Thanks!

_swarmii


Solution

  • This sounds like you should be using the serialization library (install via Pub).

    Here's a simple example to get you started:

    import 'dart:io';
    import 'package:serialization/serialization.dart';
    
    class Address {
      String street;
      int number;
    }
    
    main() {
      var address = new Address()
        ..number = 5
        ..street = 'Luumut';
    
      var serialization = new Serialization()
        ..addRuleFor(address);
    
      Map output = serialization.write(address, new SimpleJsonFormat());
    
      print(output);
    }
    

    Then depending on what you want to do exactly, I'm sure you can fine tune the code for your purpose.