Skip to content

Conversation

zimmski
Copy link
Collaborator

@zimmski zimmski commented Nov 3, 2016

This PR basically refactors the test code completely, the rest is moved around and sometimes refactored.

The goals are:

  • Refactor the code so it is only one code style
  • Split the code up into logical files
  • Reuse as much code as possible.
  • Try to use the same variable names for the same functionality
  • In general: Make the whole code more contributor friendly

It might be a good idea to look at each commit of the PR instead of the complete changes.

Fixes #43

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 98.704% when pulling da74551 on 43-refactor into 552b4e9 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 98.881% when pulling 19bf053 on 43-refactor into 552b4e9 on master.

@zimmski
Copy link
Collaborator Author

zimmski commented Nov 3, 2016

This is the coverage after refactoring the tests but before moving code around https://coveralls.io/builds/8655582 it is the same coverage as the current master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 98.881% when pulling e45989c on 43-refactor into 552b4e9 on master.

@zimmski zimmski force-pushed the 43-refactor branch 2 times, most recently from 627132d to 435c112 Compare November 3, 2016 22:37
@coveralls
Copy link

Coverage Status

Coverage increased (+0.09%) to 98.976% when pulling 435c112 on 43-refactor into 552b4e9 on master.

@zimmski
Copy link
Collaborator Author

zimmski commented Nov 3, 2016

@sergi: It would be good if you could give me some feedback on this. I will refactor the rest of the code like in the last commit here 435c112. I will basically refactor everything to be of one consistent code style, cleanup wherever I see something that could be done immediately (or add a "help wanted" issue) and basically make everything use Go idioms.

Copy link

@marxriedl marxriedl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a lot of that boils down to your preference
if it is arguably better, i really don't know
the file movements i think made sense
the table driven tests could use a little refactoring, i think that a lot of functionality could be unified/simplified

func Benchmark_DiffMainLarge(b *testing.B) {
s1 := readFile("speedtest1.txt", b)
s2 := readFile("speedtest2.txt", b)
s1 := readFile("../testdata/speedtest1.txt", b)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

introduce constant for "../testdata", maybe even for speedtest1/2.txts

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

b := "I am the very model of a modern major general,\nI've information vegetable, animal, and mineral,\nI know the kings of England, and I quote the fights historical,\nFrom Marathon to Waterloo, in order categorical.\n"
func BenchmarkDiffMain(bench *testing.B) {
s1 := "`Twas brillig, and the slithy toves\nDid gyre and gimble in the wabe:\nAll mimsy were the borogoves,\nAnd the mome raths outgrabe.\n"
s2 := "I am the very model of a modern major general,\nI've information vegetable, animal, and mineral,\nI know the kings of England, and I quote the fights historical,\nFrom Marathon to Waterloo, in order categorical.\n"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s1, s2 is not necessarily better than a, b

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true, but the whole code base uses *1&*2 more often than just a&b

s2 := "I am the very model of a modern major general,\nI've information vegetable, animal, and mineral,\nI know the kings of England, and I quote the fights historical,\nFrom Marathon to Waterloo, in order categorical.\n"

// Increase the text lengths by 1024 times to ensure a timeout.
for x := 0; x < 10; x++ {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, whatever this is and does i hope it does its job

// Null case.
assert.Equal(t, 0, dmp.DiffCommonPrefix("abc", "xyz"), "'abc' and 'xyz' should not be equal")
func TestDiffCommonPrefix(t *testing.T) {
type TestCase struct {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theres a lot of similar TestCase types, unify and extract

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to not reuse the TestCase types. The reason is that that way I can keep them inside the test function. They are not exported and the way a test function is made stays always the same without the need to find the right TestCase type.

dmp := New()
dmp.DiffTimeout = 200 * time.Millisecond

a := "`Twas brillig, and the slithy toves\nDid gyre and gimble in the wabe:\nAll mimsy were the borogoves,\nAnd the mome raths outgrabe.\n"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider constant

dmp.DiffTimeout = 200 * time.Millisecond

a := "`Twas brillig, and the slithy toves\nDid gyre and gimble in the wabe:\nAll mimsy were the borogoves,\nAnd the mome raths outgrabe.\n"
b := "I am the very model of a modern major general,\nI've information vegetable, animal, and mineral,\nI know the kings of England, and I quote the fights historical,\nFrom Marathon to Waterloo, in order categorical.\n"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider constant

@coveralls
Copy link

Coverage Status

Coverage increased (+0.09%) to 98.976% when pulling 2be755f on 43-refactor into 647f90b on master.

@zimmski zimmski changed the title WIP Refactor everything Refactor everything Dec 2, 2016
@zimmski zimmski merged commit d7be4c8 into master Dec 2, 2016
@zimmski zimmski deleted the 43-refactor branch December 2, 2016 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants