diff options
author | Nick White <git@njw.name> | 2020-08-03 16:53:43 +0100 |
---|---|---|
committer | Nick White <git@njw.name> | 2020-08-03 16:53:43 +0100 |
commit | 7fa913da473caae893b6791d9f5fb10ca1472360 (patch) | |
tree | c5e25843a1529b77b3a23097b5df930bde79cd1a | |
parent | 356b839c5f1ddfea0f0a380c6871b36bb1f7ec00 (diff) |
Update example code to run without testdata
-rw-r--r-- | example_test.go | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/example_test.go b/example_test.go index 8958557..5dfb1b2 100644 --- a/example_test.go +++ b/example_test.go @@ -5,23 +5,24 @@ package integralimg_test import ( + "encoding/base64" "fmt" "image" "image/draw" _ "image/png" + "io" "log" - "os" + "strings" "rescribe.xyz/integralimg" ) +const smallImg = `iVBORw0KGgoAAAANSUhEUgAAAAYAAAADCAAAAACVaiEnAAAGqHpUWHRSYXcgcHJvZmlsZSB0eXBlIGV4aWYAAHjarVhbsusoDPxnFbMEEA/BcsRDVbODWf60sJOTOM69d6omrhgHZJC6pYZz3Prnb3V/4UPRF5cy19JK8fiklhoJHqo/Pm3fg0/7fnzK2Yb3fufjOUDosufzN8tpL+jPPy881gj9vd/Vc4TqOdFj5XPCaCsTHuark+inoz+kc6K2To9b5VdXOx3tOA23K+c38p76OYn9dq8diYHSzLCKRCuG6Pe9Hh7E4yv41n2HUxgteE4xu6M5PQEgb+E9Wu9fAXoH/3xyV/QfYF7BJzkt4gXL8mCt3A+EfA/+hvhl4fj0iN4HRvf8Ec75VZ1VdR3RSSpAtJwZ5d0DHXsHhh2Qx/1awcX4Zjzzvhqu6sUPkDP98B3XCC0QWFEXUphBgoa12xEGXEy0iNESDYq7r0amRiMaT8muoMSxxQkGKQ5aLkZ009OXsNdte70RKlaeAaYUMFnAK18v96vB/3I51WEQBQOzHljBL7LMhRvGnN1hBUKCnrzlDfDjOun3L4mFVAWDecNcEaD4fkzRc/jJrbh5jrDLaI+qCI7nOQEgwtoZzoQIBnwJMYcSPBNxCMCxgiCB5xQ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lIFJWMhMlYGBiUFIVUiIAQAu0QMPFiP3IQAAAABJRU5ErkJggg==` + +func smallImgPNG() io.Reader { return base64.NewDecoder(base64.StdEncoding, strings.NewReader(smallImg)) } + func ExampleImage_Sum() { - f, err := os.Open("testdata/in.png") - if err != nil { - log.Fatal(err) - } - defer f.Close() - img, _, err := image.Decode(f) + img, _, err := image.Decode(smallImgPNG()) if err != nil { log.Fatal(err) } @@ -30,16 +31,11 @@ func ExampleImage_Sum() { draw.Draw(integral, b, img, b.Min, draw.Src) fmt.Printf("Sum: %d\n", integral.Sum(b)) // Output: - // Sum: 601340165 + // Sum: 551008 } func ExampleImage_Mean() { - f, err := os.Open("testdata/in.png") - if err != nil { - log.Fatal(err) - } - defer f.Close() - img, _, err := image.Decode(f) + img, _, err := image.Decode(smallImgPNG()) if err != nil { log.Fatal(err) } @@ -48,16 +44,11 @@ func ExampleImage_Mean() { draw.Draw(integral, b, img, b.Min, draw.Src) fmt.Printf("Mean: %f\n", integral.Mean(b)) // Output: - // Mean: 54677.229042 + // Mean: 30611.555556 } func ExampleMeanStdDev() { - f, err := os.Open("testdata/in.png") - if err != nil { - log.Fatal(err) - } - defer f.Close() - img, _, err := image.Decode(f) + img, _, err := image.Decode(smallImgPNG()) if err != nil { log.Fatal(err) } @@ -69,5 +60,5 @@ func ExampleMeanStdDev() { mean, stddev := integralimg.MeanStdDev(*integral, *sqIntegral, b) fmt.Printf("Mean: %f, Standard Deviation: %f\n", mean, stddev) // Output: - // Mean: 54677.229042, Standard Deviation: 21643.721672 + // Mean: 30611.555556, Standard Deviation: 25372.651592 } |