Giter VIP home page Giter VIP logo

workshop_unit_test's Introduction

TDD

Ref: Modern C++ Programming with Test-driven development by Jeff Langr

Effective Modern C++ by Scott Meyers

  • Location 1620: C++ forbids reference to bits - auto in bool might be dangerous
  • Location 1745: instead of C-style casting like (int)d, use static_cast<int> (d)
  • Location 1863: uniform initializatio or braced initialization
    • int x(0);
    • int x= 0;
    • int x {0};
    • {} can be used anywhere. x(0) may not work in the class declaration. x=0 may not work for atomic
    • But {} checks type more strictly. Casting or type conversion will work with () or =
    • In overloading of constructors, it will prefer initialization_list
    • std::vector v1(10,20); 10 length vector with value of 20
    • std::vector v1{10,20}; a single vector with 2 elements of 10,20
  • Location 2342: typedef => using

Best practice of C++11

  • Pass by value vs pass by const address
  • Using unique pointer
    • Allocate dynamic array using new while delete is not required. Garbage collection
    • Not suitable for MPI communication. Use STL instead
    • Legacy pointer : requires delete
    int *x;
    x = new int (4);
    ...
    delete[] x;
    
    • std::unique_ptr : garbage collection. no delete
    std::unique_ptr<int[]> v {new int [4]}
    
    • Using make_unique (since -std=c++14) : garbage collection. no delete
    std::unique_ptr<int[]> w;
    w = std::make_unique<int[]>(4);
    

Valgrind

  • Detection of uninitialized variables are done when the variables are compared
  • Assigning uninitialized value is NOT detected

ctest from cmake

  • ctest # run all tests - unit test, regression test, ...
  • ctest -L some_test # run some_test among all tests
  • ctest -LE some_test # run all tests but some_test
  • ctest --timeout 1000 # each test will use time out 1000 sec
  • ctest -R my_unit_test_01 # run one set named my_unit_test_01 among all tests
  • ctest -VV -R my_unit_test_01 # run one set named my_unit_test01 among all tests. Higher verbosity. stdout will be shown in the screen output

workshop_unit_test's People

Contributors

hpjeongit avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.