// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package memory_test

import (
	"github.com/cloudfoundry/java-buildpack-memory-calculator/memory"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("MemoryBucket", func() {
	var (
		DEFAULT_JRE_STACK_SIZE = memory.NewMemSize(mEGA)
		testRange              memory.Range
		testZeroRange          memory.Range
		testUBRange            memory.Range
		shouldFail             func(memory.Bucket, error)
		shouldWork             func(memory.Bucket, error) memory.Bucket
	)

	BeforeEach(func() {
		testRange = boundedMemoryRange(2*mEGA, 3*mEGA)
		testZeroRange = boundedMemoryRange(0, 4*mEGA)
		testUBRange = unboundedMemoryRange(10 * kILO)

		shouldFail = func(b memory.Bucket, err error) {
			Ω(b).Should(BeNil())
			Ω(err).Should(HaveOccurred())
			})

			Context("with no memory and no buckets", func() {
				BeforeEach(func() {
					sizes = strmap{"heap": "0.."}
					weights = floatmap{}
					memLimit = memory.MEMSIZE_ZERO
				})
				It("fails", func() {})
			})

			Context("with not enough memory and one bucket", func() {
				BeforeEach(func() {
					sizes = strmap{"heap": "64m.."}
					weights = floatmap{"heap": 5.0}
					memLimit = memory.NewMemSize(32 * mEGA)
				})
				It("fails", func() {})
			})

			Context("with not enough memory and two buckets", func() {
				BeforeEach(func() {
					sizes = strmap{"heap": "33m..", "hope": "32m.."}
					weights = floatmap{"heap": 1.0, "hope": 1.0}
					memLimit = memory.NewMemSize(64 * mEGA)
				})
				It("fails", func() {})
			})

			Context("with just enough memory for one out of two buckets", func() {
				BeforeEach(func() {
func getMs(msInt int64) memory.MemSize {
	return memory.NewMemSize(msInt)
}