This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| def simulate(a, b, iterations): | |
| acount = bcount = 0 | |
| for i in xrange(iterations): | |
| vala = random.uniform(0, a) | |
| valb = random.uniform(0, b) | |
| if vala > valb: | |
| acount+=1 | |
| elif vala < valb: | |
| bcount += 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 75a76 | |
| > num_setable = 0; | |
| 271c272 | |
| < int num_setable = 0; | |
| --- | |
| > int num_setable; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func ItemTest(t *testing.T) { | |
| // Common setup. Abstract this out | |
| // This allows each test to create its own handler by changing handler variable | |
| handler := http.NotFound | |
| hs := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { | |
| handler(rw, req) | |
| })) | |
| defer hs.Close() | |
| // Notice I set the base URL of the client to the httptest server | |
| c := Client{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type roundTripFunc func (r *http.Request) (*http.Response, error) | |
| func (s roundTripFunc) RoundTrip(r *http.Request) (*http.Response, error) { | |
| return s(r) | |
| } | |
| func TestSword(t *testing.T) { | |
| var c Client | |
| c.Client.Transport = roundTripFunc(func(r *http.Request) (*http.Response, error) { | |
| assert.Equal(t, r.URL.Path, "/v1/item/sword") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // +build integration | |
| package smiteclient | |
| // Create a file named info.json and put it at the root of your project. That file should have your | |
| // devId and authKey. The file should be inside .gitignore and not checked into git. Then, | |
| // run `go test -v --tags=integration .` to start integration tests using your auth key. | |
| type devInfo struct { | |
| AuthKey string | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func (c *Client) doRequest(req *http.Request) { | |
| resp, err := c.client.Do(req) | |
| if err != nil { | |
| return err | |
| } | |
| defer func() { | |
| maxCopySize := 2 << 10 | |
| io.CopyN(ioutil.Discard, resp.Body, maxCopySize) | |
| resp.Close() | |
| }() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const DefaultBaseURL = "http://api.smitegame.com/" | |
| func (c *Client) urlBase() string { | |
| if c.BaseURL == "" { | |
| return DefaultBaseURL | |
| } | |
| return c.BaseURL | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "fmt" | |
| import "golang.org/x/net/context" | |
| // A message processes parameter and returns the result on responseChan. | |
| // ctx is places in a struct, but this is ok to do. | |
| type message struct { | |
| responseChan chan<- int | |
| parameter string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package goexperiments | |
| import ( | |
| "context" | |
| "net/http" | |
| ) | |
| type HandlerMiddleware interface { | |
| HandleHTTPC(ctx context.Context, rw http.ResponseWriter, req *http.Request, next http.Handler) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package goexperiments | |
| import ( | |
| "context" | |
| "net/http" | |
| ) | |
| type HandlerMiddleware interface { | |
| HandleHTTPC(ctx context.Context, rw http.ResponseWriter, req *http.Request, next http.Handler) | |
| } |
OlderNewer